Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created November 19, 2010 21:18
Show Gist options
  • Save indexzero/707193 to your computer and use it in GitHub Desktop.
Save indexzero/707193 to your computer and use it in GitHub Desktop.
Sample usage for the proposed addHead addition to ServerResponse
var http = require('http');
//
// Open Questions here:
// 1. Does writeHead always have to be called if setHeader is called?
// 2. Does writeHead always have to be called with a statusCode?
// 3. Can setHeader be called after writeHead?
// 4. Does setHeader take a statusCode?
//
http.createServer(function (req, res) {
var content = 'hello, i know nodejs.';
res.setHeader('Content-Length', content.length);
res.writeHead(200, {'Content-Type': 'text/plain'});
res.setHeader('Should-This', 'Be-Allowed?');
res.write(content);
res.end();
}).listen(8080);
@Marak
Copy link

Marak commented Nov 19, 2010

I'm about to post on dev list, would appreciate feedback on there.

@indexzero
Copy link
Author

Agree with your comments Alexis, updated gist.

@Marak
Copy link

Marak commented Nov 19, 2010

Started repo to implement new response object as a CommonJS module:

https://github.com/Marak/response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment