diff --git a/lib/http.js b/lib/http.js index dc7169875b7..e6e416f3637 100644 --- a/lib/http.js +++ b/lib/http.js @@ -109,11 +109,8 @@ exports.parseUri.options = { }; -var connection_expression = /Connection/i; -var transfer_encoding_expression = /Transfer-Encoding/i; var close_expression = /close/i; var chunk_expression = /chunk/i; -var content_length_expression = /Content-Length/i; /* Abstract base class for ServerRequest and ClientResponse. */ @@ -245,15 +242,15 @@ OutgoingMessage.prototype.sendHeaderLines = function (first_line, headers) { message_header += field + ": " + value + CRLF; - if (connection_expression.exec(field)) { + if ("connection" === field) { sent_connection_header = true; if (close_expression.exec(value)) this.closeOnFinish = true; - } else if (transfer_encoding_expression.exec(field)) { + } else if ("transfer-encoding" === field) { sent_transfer_encoding_header = true; if (chunk_expression.exec(value)) this.chunked_encoding = true; - } else if (content_length_expression.exec(field)) { + } else if ("content-length" === field) { sent_content_length_header = true; } diff --git a/src/http.cc b/src/http.cc index 841ccbd6f48..53edb576079 100644 --- a/src/http.cc +++ b/src/http.cc @@ -128,12 +128,28 @@ HTTPConnection::on_fragment (http_parser *parser, const char *buf, size_t len) return 0; } +const static char normalizer[] = + "\0------------------------------" + "-----------------0123456789-----" + "--abcdefghijklmnopqrstuvwxyz----" + "--abcdefghijklmnopqrstuvwxyz----" + "--------------------------------" + "--------------------------------" + "--------------------------------" + "--------------------------------"; + int HTTPConnection::on_header_field (http_parser *parser, const char *buf, size_t len) { HandleScope scope; HTTPConnection *connection = static_cast(parser->data); assert(connection->attached_); + + // NORMALIZE + size_t i; + char *nonconstbuf = (char*)buf; // FIXME + for (i = 0; i < len; i++) { nonconstbuf[i] = normalizer[buf[i]]; } + Local argv[1] = { String::New(buf, len) }; connection->Emit("headerField", 1, argv); return 0; @@ -145,6 +161,7 @@ HTTPConnection::on_header_value (http_parser *parser, const char *buf, size_t le HandleScope scope; HTTPConnection *connection = static_cast(parser->data); assert(connection->attached_); + Local argv[1] = { String::New(buf, len) }; connection->Emit("headerValue", 1, argv); return 0; diff --git a/test/mjsunit/test-http.js b/test/mjsunit/test-http.js index ebdd6ee4f87..4cc7753ccd4 100644 --- a/test/mjsunit/test-http.js +++ b/test/mjsunit/test-http.js @@ -13,11 +13,11 @@ http.createServer(function (req, res) { assertEquals("/hello", req.uri.path); p(req.headers); - assertTrue("Accept" in req.headers); - assertEquals("*/*", req.headers["Accept"]); + assertTrue("accept" in req.headers); + assertEquals("*/*", req.headers["accept"]); - assertTrue("Foo" in req.headers); - assertEquals("bar", req.headers["Foo"]); + assertTrue("foo" in req.headers); + assertEquals("bar", req.headers["foo"]); } if (responses_sent == 1) {