Created
March 8, 2012 19:13
-
-
Save duggan/2002769 to your computer and use it in GitHub Desktop.
Node.js script. Spits out the headers of a request - useful for basic remote request testing
This file contains 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
var http = require('http'); | |
var qs = require('querystring'); | |
/* Host / Port configuration. | |
Defaults to listening on all interfaces, port 80. | |
*/ | |
var host = "0.0.0.0"; | |
var port = 80; | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end("Hello world!"); | |
console.log("\n") | |
console.log(req.method + ": " + req.headers.host + req.url) | |
console.log(req["headers"]); | |
if (req.method in {'POST':'', 'PUT':'', 'DELETE':''}) { | |
var body = '' | |
req.on('data', function (data) { | |
body += data; | |
}); | |
req.on('end', function () { | |
console.log(qs.parse(body)); | |
}); | |
} | |
}).listen(port, host); | |
console.log('Server running'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment