Created
November 19, 2010 21:18
-
-
Save indexzero/707193 to your computer and use it in GitHub Desktop.
Sample usage for the proposed addHead addition to ServerResponse
This file contains hidden or 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'); | |
// | |
// 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); |
I'm about to post on dev list, would appreciate feedback on there.
Agree with your comments Alexis, updated gist.
Started repo to implement new response object as a CommonJS module:
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1, I really need this functionality to stay sane.
But I would make the API more similar to XMLHTTPRequest:
Or rename it to
setHeaders
. 'Head' assumes the status code.And in answer to your questions: