duplicate http headers should not be dropped #2750
Comments
Here is the change for the master branch: jolira@9392bee |
I hate going all standards lawyer on people but RFC 2616, section 4.2 has this to say about multiple headers:
Node is doing the right (or at least the standards approved) thing here by concatenating headers that are allowed to exist multiple times, like Accept-Encoding, and dropping duplicates of other headers, like the DAV header in your example. For the sake of usability we could change that behaviour to, for example, concatenate "unknown" headers like we do for X-prefixed headers. Thoughts anyone? |
I would like to store ALL the multiple headers (even if they are invalid) as an array. But it may be related to #1448. |
You may want to take a look at this section of RFC 4918: http://tools.ietf.org/html/rfc4918#section-10.1
It seems like comma-delimiting values of duplicate headers it would work for the WebDAV. |
The 2D-header array proposed in #1448 would address this issue. |
I can work around this issue successfully by requiring the this file when starting my server: https://raw.github.com/jolira/node-subversion-hub/master/lib/http-patch.js |
This issue just bit me. Node can't possibly know what headers "may" permit multiple values, because (1) I can define my own and (2) as of RFC6648 there's no easy way for you to know I've just made up a header (like looking for "X-"). |
@cbiffle Is this still relevant now that incoming messages have a var http = require('http');
var net = require('net');
var req =
'OPTIONS /svn HTTP/1.1\r\n'+
'User-Agent: SVN/1.7.2 neon/0.29.6\r\n'+
'Keep-Alive: \r\n'+
'Connection: TE, Keep-Alive\r\n'+
'TE: trailers\r\n'+
'Host: jolira-tools.googlecode.com\r\n'+
'Content-Type: text/xml\r\n'+
'Accept-Encoding: gzip\r\n'+
'DAV: http://subversion.tigris.org/xmlns/dav/svn/depth\r\n'+
'DAV: http://subversion.tigris.org/xmlns/dav/svn/mergeinfo\r\n'+
'DAV: http://subversion.tigris.org/xmlns/dav/svn/log-revprops\r\n'+
'Content-Length: 104\r\n'+
'Accept-Encoding: gzip\r\n'+
'\r\n'+
'<?xml version="1.0" encoding="utf-8"?><D:options xmlns:D="DAV:"><D:activity-collection-set/></D:options>HTTP/1.1 200 OK\r\n';
var server = http.createServer(function(req, res) {
console.error(req.rawHeaders);
console.error(req.headers);
res.setHeader('connection', 'close');
res.setHeader('content-length', '2');
res.end('ok');
server.close();
});
server.listen(1337, function() {
var client = net.connect(1337, function() {
client.pipe(process.stdout);
});
client.end(req);
});
/*
[ 'User-Agent',
'SVN/1.7.2 neon/0.29.6',
'Keep-Alive',
'',
'Connection',
'TE, Keep-Alive',
'TE',
'trailers',
'Host',
'jolira-tools.googlecode.com',
'Content-Type',
'text/xml',
'Accept-Encoding',
'gzip',
'DAV',
'http://subversion.tigris.org/xmlns/dav/svn/depth',
'DAV',
'http://subversion.tigris.org/xmlns/dav/svn/mergeinfo',
'DAV',
'http://subversion.tigris.org/xmlns/dav/svn/log-revprops',
'Content-Length',
'104',
'Accept-Encoding',
'gzip' ]
{ 'user-agent': 'SVN/1.7.2 neon/0.29.6',
'keep-alive': '',
connection: 'TE, Keep-Alive',
te: 'trailers',
host: 'jolira-tools.googlecode.com',
'content-type': 'text/xml',
'accept-encoding': 'gzip, gzip',
dav: 'http://subversion.tigris.org/xmlns/dav/svn/depth',
'content-length': '104' }
HTTP/1.1 200 OK
connection: close
content-length: 2
Date: Tue, 27 Aug 2013 18:21:11 GMT
ok
*/ |
Multiple response headers will be stored as an array, and passed to the Node.js `ServerResponse`. See http://nodejs.org/api/http.html#http_response_setheader_name_value and nodejs/node-v0.x-archive#2750
http headers can very legitimately contain duplicate header variables. For instance, when working with WebDAV duplicate headers are used frequently. Here is an example for a header used by subversion:
Other languages (such as Java) use an array to store headers for that reason.
The code change to support an array in lib/http.js is rather simple. I prototyped it in jolira@0face42.
The text was updated successfully, but these errors were encountered: