Skip to content

Instantly share code, notes, and snippets.

@domenic
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domenic/2bb318b53946cf148279 to your computer and use it in GitHub Desktop.
Save domenic/2bb318b53946cf148279 to your computer and use it in GitHub Desktop.
Node's default HTTP request headers
"use strict";
var http = require("http");
http.createServer(function (req) {
console.log(req.headers);
})
.listen(1337);
http.get('http://localhost:1337');
// { host: 'localhost:1337', connection: 'close' }
var req = http.request({ hostname: 'localhost', port: 1337, path: '/', method: 'POST' });
req.write('data');
req.end();
// { host: 'localhost:1337', connection: 'close', 'transfer-encoding': 'chunked' }
var req2 = http.request({ hostname: 'localhost', port: 1337, path: '/', method: 'POST', headers: { 'content-length': 4 } });
req2.write('data');
req2.end();
// { 'content-length': 4, host: 'localhost:1337', connection: 'close' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment