Created
September 18, 2018 19:26
-
-
Save kuryaki/b85a8043d27cec608ac3508f86255681 to your computer and use it in GitHub Desktop.
Minimal HTTP server that prints request information in rfc 2616
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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