Get and Set a Single Cookie with Node.js HTTP Server

There is no quick function access to getting/setting cookies, so I came up with the following hack: const http = require(‘http’); function parseCookies (request) { const list = {}; const cookieHeader = request.headers?.cookie; if (!cookieHeader) return list; cookieHeader.split(`;`).forEach(function(cookie) { let [ name, …rest] = cookie.split(`=`); name = name?.trim(); if (!name) return; const value = rest.join(`=`).trim(); … Read more

Simple HTTP server in Java using only Java SE API

Since Java SE 6, there’s a builtin HTTP server in Sun Oracle JRE. The Java 9 module name is jdk.httpserver. The com.sun.net.httpserver package summary outlines the involved classes and contains examples. Here’s a kickoff example copypasted from their docs. You can just copy’n’paste’n’run it on Java 6+. (to all people trying to edit it nonetheless, … Read more

What is a faster alternative to Python’s http.server (or SimpleHTTPServer)?

http-server for node.js is very convenient, and is a lot faster than Python’s SimpleHTTPServer. This is primarily because it uses asynchronous IO for concurrent handling of requests, instead of serialising requests. Installation Install node.js if you haven’t already. Then use the node package manager (npm) to install the package, using the -g option to install … Read more