indexzero
11/19/2010 - 9:18 PM

Sample usage for the proposed addHead addition to ServerResponse

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);