Skip to content

Instantly share code, notes, and snippets.

@CoDEmanX
Created August 19, 2015 16:15
Show Gist options
  • Save CoDEmanX/41ae8879afecb9a13a98 to your computer and use it in GitHub Desktop.
Save CoDEmanX/41ae8879afecb9a13a98 to your computer and use it in GitHub Desktop.
NodeJS: parse HTTP header string
var http = require("http");
var net = require("net");
var server = http.createServer(function (req, res) {
console.dir(req.headers);
console.dir(req.url);
server.close();
});
server.listen(8080);
var client = net.connect(8080, "localhost", function(){
client.write("POST /index.html HTTP/1.1\n" +
"Host: www.example.org\n" +
"User-Agent: Mozilla/4.0\n" +
"Accept: image/gif, image/jpeg, */*\n" +
"Connection: close\n\n"
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment