Skip to content

Commit ab1991a

Browse files
authored
Merge pull request #16 from fbbdev/content-length-type
Fix CONTENT_TYPE and CONTENT_LENGTH handling
2 parents b4612a5 + 71be407 commit ab1991a

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

lib/request.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ Request.prototype._createReqRes = function () {
122122

123123
for (var param in this.params) {
124124
if (HEADER_EXPR.test(param) || param === 'CONTENT_LENGTH' || param === 'CONTENT_TYPE') {
125-
var name = param.slice(5).replace(UNDERSCORE_EXPR, '-');
125+
var name = param.replace(HEADER_EXPR, '').replace(UNDERSCORE_EXPR, '-');
126+
127+
// Ignore HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH
128+
if (HEADER_EXPR.test(param) && (name.toLowerCase() === 'content-type' || name.toLowerCase() === 'content-length'))
129+
continue;
130+
126131
var value = this.params[param];
127132
raw.push(name, value);
128133
this._req._addHeaderLine(name, value, dest);

test/mocha/integration/echo.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,18 @@ describe('echo Server', function setup() {
194194

195195
it('should answer with correct request header names', function checkResponse(done) {
196196
var hdr1 = 'test1',
197-
hdr2 = 'test2';
197+
hdr2 = 'test2',
198+
cl = '23',
199+
ct = 'text/plain';
198200

199201
request({
200202
uri: 'http://localhost:' + port,
201203
method: 'GET',
202204
headers: {
203-
'x_testhdr': hdr1, // XXX: Using underscores because fcgi-handler
204-
'x_test_hdr': hdr2 // passes hyphens in CGI params
205+
'x_testhdr': hdr1, // XXX: Using underscores because fcgi-handler
206+
'x_test_hdr': hdr2, // passes hyphens in CGI params
207+
'content-length': cl,
208+
'content-type': 'text/plain'
205209
}
206210
}, function (err, res, body) {
207211
expect(res.statusCode).to.be.equal(200);
@@ -210,6 +214,8 @@ describe('echo Server', function setup() {
210214
var echo = JSON.parse(body);
211215
expect(echo).to.have.deep.property('headers.x-testhdr', hdr1);
212216
expect(echo).to.have.deep.property('headers.x-test-hdr', hdr2);
217+
expect(echo).to.have.deep.property('headers.content-length', cl);
218+
expect(echo).to.have.deep.property('headers.content-type', ct);
213219

214220
done(err);
215221
});

0 commit comments

Comments
 (0)