patch for http.js client response headers handling...

62 views
Skip to first unread message

billywhizz

unread,
Feb 3, 2010, 5:46:02 AM2/3/10
to nodejs
I have created a patch which i have tested myself while doing a lot of
work with the client side features of the http library. As far as i
can see the way it handles headers is broken as all it does is
concatenate them into a big string, which is pretty impossible to
parse with a comma as the only delimiter. i have made a change that i
use locally to instead store an array against the client.headers
object. each header gets a new array element, even if the header name
is a duplicate (which is perfectly legal in http).

this may well break a lot of code that uses the http library so it may
be better to make a separate headersarray property on the http client
function instead.

any thoughts?

http://gist.github.com/293534

usage:

instead of parsing through the headers in the response, you can now
iterate them as an array:

e.g

res.headers["set-cookie"].forEach( function( cookie ) {
props = cookie.split(";");
};

Isaac Z. Schlueter

unread,
Feb 3, 2010, 1:07:33 PM2/3/10
to nodejs
So, I have a branch with a similar change, but which also lets you
*send* headers as an array of values. (So, for instance, you can set
more than one cookie in a single response, without resorting to odd
hacks.)

The problem is that it breaks the multipart library. I've pinged
Felix to look at it, but haven't heard from him, and I haven't had a
chance to thoroughly comb through the issues myself.

The branch is here: http://github.com/isaacs/node/commits/jsgi-header-fast

The benefit of this is that node would take the same structure for the
header object that JSGI specifies. The only thing standing in the way
is the multipart parsing incompatibility.

--i

Reply all
Reply to author
Forward
0 new messages