Skip to content

Instantly share code, notes, and snippets.

@kuryaki
Created September 18, 2018 19:26
Show Gist options
  • Select an option

  • Save kuryaki/b85a8043d27cec608ac3508f86255681 to your computer and use it in GitHub Desktop.

Select an option

Save kuryaki/b85a8043d27cec608ac3508f86255681 to your computer and use it in GitHub Desktop.
Minimal HTTP server that prints request information in rfc 2616
const http = require('http');
const server = http.createServer((req, res) => {
let body = '';
req.on('data', chunk => {
body += chunk;
});
req.on('end', () => {
console.log(`${req.method} ${req.url} HTTP/${req.httpVersion}\n`)
Object.entries(req.headers).forEach(([key, val]) => {
console.log(`${key}: ${val}`);
});
console.log(`\n${body}`);
});
res.end();
});
server.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment