Skip to content

Fix CONTENT_TYPE and CONTENT_LENGTH handling #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ Request.prototype._createReqRes = function () {

for (var param in this.params) {
if (HEADER_EXPR.test(param) || param === 'CONTENT_LENGTH' || param === 'CONTENT_TYPE') {
var name = param.slice(5).replace(UNDERSCORE_EXPR, '-');
var name = param.replace(HEADER_EXPR, '').replace(UNDERSCORE_EXPR, '-');

// Ignore HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH
if (HEADER_EXPR.test(param) && (name.toLowerCase() === 'content-type' || name.toLowerCase() === 'content-length'))
continue;

var value = this.params[param];
raw.push(name, value);
this._req._addHeaderLine(name, value, dest);
Expand Down
12 changes: 9 additions & 3 deletions test/mocha/integration/echo.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,18 @@ describe('echo Server', function setup() {

it('should answer with correct request header names', function checkResponse(done) {
var hdr1 = 'test1',
hdr2 = 'test2';
hdr2 = 'test2',
cl = '23',
ct = 'text/plain';

request({
uri: 'http://localhost:' + port,
method: 'GET',
headers: {
'x_testhdr': hdr1, // XXX: Using underscores because fcgi-handler
'x_test_hdr': hdr2 // passes hyphens in CGI params
'x_testhdr': hdr1, // XXX: Using underscores because fcgi-handler
'x_test_hdr': hdr2, // passes hyphens in CGI params
'content-length': cl,
'content-type': 'text/plain'
}
}, function (err, res, body) {
expect(res.statusCode).to.be.equal(200);
Expand All @@ -210,6 +214,8 @@ describe('echo Server', function setup() {
var echo = JSON.parse(body);
expect(echo).to.have.deep.property('headers.x-testhdr', hdr1);
expect(echo).to.have.deep.property('headers.x-test-hdr', hdr2);
expect(echo).to.have.deep.property('headers.content-length', cl);
expect(echo).to.have.deep.property('headers.content-type', ct);

done(err);
});
Expand Down