diff --git a/src/infinite-server/infinite-server-constants.js b/src/infinite-server/infinite-server-constants.js deleted file mode 100644 index 637d899..0000000 --- a/src/infinite-server/infinite-server-constants.js +++ /dev/null @@ -1,15 +0,0 @@ -const INTERVAL_TIME = 200; -const CONTENT_LENGTH = 100; -const HTTP_PORT = 8080; -const HTTPS_PORT = 8443; -const HTTP1MSSG = 'Infinite server endpoint (HTTP/1.1)\n'; -const HTTP2MSSG = 'Infinite server endpoint (HTTP/2)\n'; - -module.exports = { - INTERVAL_TIME, - CONTENT_LENGTH, - HTTP_PORT, - HTTPS_PORT, - HTTP1MSSG, - HTTP2MSSG, -}; diff --git a/src/infinite-server/infinite-server-http.js b/src/infinite-server/infinite-server-http.js deleted file mode 100644 index 1fb6fb1..0000000 --- a/src/infinite-server/infinite-server-http.js +++ /dev/null @@ -1,32 +0,0 @@ -const http = require('node:http'); -const { INTERVAL_TIME, HTTP1MSSG, HTTP_PORT } = require('./infinite-server-constants'); - -const server = http.createServer((req, res) => { - res.writeHead(200, { - 'Content-Type': 'text/plain', - // ! Stream will abort once DATA size is larger than the Content-Length header (if specified) - // ! Ommiting the content-length header will allow the stream to be infinite - // ? Not found anything in the specs about having to close the stream, yet. - // * TD: figure out if this is Node.js specific or HTTP/1.1 specific - // 'Content-Length': cons.CONTENT_LENGTH - }); - - if (req.url === '/infinite') { - // Infinite response cycle - const interval = setInterval(() => { - res.write(`${req.url.slice(1)}\n`); - }, INTERVAL_TIME); - - req.on('close', () => { - clearInterval(interval); - res.end(); - }); - - return; - } - - res.write(HTTP1MSSG); - res.end(); -}); - -server.listen(HTTP_PORT); diff --git a/src/infinite-server/infinite-server-http2.js b/src/infinite-server/infinite-server-http2.js deleted file mode 100644 index 804e997..0000000 --- a/src/infinite-server/infinite-server-http2.js +++ /dev/null @@ -1,47 +0,0 @@ -const http2 = require('node:http2'); -const fs = require('node:fs'); -const { INTERVAL_TIME, HTTP2MSSG, HTTPS_PORT } = require('./infinite-server-constants'); - -/* eslint no-sync: ["error", { allowAtRootLevel: true }] */ -const server = http2.createSecureServer({ - key: fs.readFileSync('localhost-privkey.pem'), - cert: fs.readFileSync('localhost-cert.pem'), -}); -/// server.on('error', err => console.error(err)); - -server.on('stream', (stream, headers) => { - const path = headers[':path']; - - if (path === '/infinite') { - stream.respond({ - 'content-type': 'text/plain', - ':status': 200, - // ! Stream will abort once DATA size is larger than the Content-Length header (if specified) - // ! Ommiting the content-length header will allow the stream to be infinite - // * See also https://datatracker.ietf.org/doc/html/rfc9113#name-malformed-messages - // * TD: figure out if this is Node.js specific or HTTP/2 specific - // 'content-length': cons.CONTENT_LENGTH - }); - - // Infinite response cycle - const interval = setInterval(() => { - stream.write(`${path.slice(1)}\n`); - }, INTERVAL_TIME); - - stream.on('close', () => { - clearInterval(interval); - stream.end(); - }); - - return; - } - - stream.respond({ - 'content-type': 'text/html', - ':status': 200, - }); - - stream.end(HTTP2MSSG); -}); - -server.listen(HTTPS_PORT);