Skip to content

Commit f386c8d

Browse files
committed
Correctly handle underscores in CGI param names
Fixes #5
1 parent ab2bd60 commit f386c8d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/request.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ function Request(conn, id, role, keepalive) {
7474
}
7575
util.inherits(Request, InputStream);
7676

77-
Request.headerExpression = /^HTTP_/;
78-
7977
Request.prototype.close = function() {
8078
delete this.connection.requests[this.id];
8179
if (!this.keepalive) this.connection.socket.end();
@@ -85,6 +83,9 @@ Request.prototype.close = function() {
8583
this.emit('close');
8684
};
8785

86+
var headerExpr = /^HTTP_/;
87+
var underscoreExpr = /_/g;
88+
8889
Request.prototype._param = function(name, value) {
8990
this.cgiParams[name] = value;
9091

@@ -95,8 +96,8 @@ Request.prototype._param = function(name, value) {
9596
if (this._queryString) this.url += '?' + this._queryString;
9697
}
9798

98-
if (Request.headerExpression.test(name)) {
99-
field = name.slice(5).replace('_', '-').toLowerCase();
99+
if (headerExpr.test(name)) {
100+
field = name.slice(5).replace(underscoreExpr, '-').toLowerCase();
100101
if (this.headers[field] === undefined) this.headers[field] = value;
101102
}
102103

0 commit comments

Comments
 (0)