Skip to content

Instantly share code, notes, and snippets.

@afeld
Created November 5, 2014 16:46
Show Gist options
  • Save afeld/907334aaa586d885a12b to your computer and use it in GitHub Desktop.
Save afeld/907334aaa586d885a12b to your computer and use it in GitHub Desktop.
zero-length response in Node
var http = require('http');
var server = http.createServer(function (request, response) {
response.setHeader('content-length', 0);
response.end();
});
server.listen(8000, function() {
console.log("Server running at http://127.0.0.1:8000/");
var req = http.request({
host: 'localhost',
port: 8000
}, function(res) {
console.log('HEADERS: ' + JSON.stringify(res.headers));
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
res.on('end', function() {
console.log('END');
});
});
req.end();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment