Created
January 28, 2010 18:16
-
-
Save isaacs/288986 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/deps/v8/tools/linux-tick-processor b/deps/v8/tools/linux-tick-processor | |
old mode 100644 | |
new mode 100755 | |
diff --git a/lib/http.js b/lib/http.js | |
index dcb152e..2bcfe1b 100644 | |
--- a/lib/http.js | |
+++ b/lib/http.js | |
@@ -88,9 +88,8 @@ IncomingMessage.prototype.resume = function () { | |
IncomingMessage.prototype._addHeaderLine = function (field, value) { | |
if (field in this.headers) { | |
- // TODO Certain headers like 'Content-Type' should not be concatinated. | |
- // See https://www.google.com/reader/view/?tab=my#overview-page | |
- this.headers[field] += ", " + value; | |
+ if (!(this.headers[field] instanceof Array)) this.headers[field] = [this.headers[field]]; | |
+ this.headers[field].push(value); | |
} else { | |
this.headers[field] = value; | |
} | |
@@ -152,16 +151,27 @@ OutgoingMessage.prototype.sendHeaderLines = function (first_line, headers) { | |
var message_header = first_line; | |
var field, value; | |
for (var i in headers) { | |
- if (headers[i] instanceof Array) { | |
+ if ((headers instanceof Array) && (headers[i] instanceof Array)) { | |
field = headers[i][0]; | |
- value = headers[i][1]; | |
+ value = headers[i].slice(1); | |
+ if (value[0] instanceof Array) value = value[0]; | |
} else { | |
if (!headers.hasOwnProperty(i)) continue; | |
field = i; | |
value = headers[i]; | |
} | |
- message_header += field + ": " + value + CRLF; | |
+ // optimize for arrays, since that's the most common thing to see here | |
+ // but, support {forEach:function..}, since that's what JSGI specs. | |
+ if (!value) value = []; | |
+ if (typeof(value.forEach) !== "function") value = [value]; | |
+ if (Array.isArray(value)) { | |
+ message_header += field + ": " + value.join(CRLF + field + ": ") + CRLF; | |
+ } else { | |
+ value.forEach(function (value) { | |
+ message_header += field + ": " + value + CRLF; | |
+ }); | |
+ } | |
if (connection_expression.test(field)) { | |
sent_connection_header = true; | |
@@ -246,7 +256,7 @@ exports.ServerResponse = ServerResponse; | |
ServerResponse.prototype.sendHeader = function (statusCode, headers) { | |
var reason = STATUS_CODES[statusCode] || "unknown"; | |
- var status_line = "HTTP/1.1 " + statusCode.toString() + " " + reason + CRLF; | |
+ var status_line = "HTTP/1.1 " + statusCode + " " + reason + CRLF; | |
this.sendHeaderLines(status_line, headers); | |
}; | |
diff --git a/test/mjsunit/test-http-server.js b/test/mjsunit/test-http-server.js | |
index 63e394b..f5e8ce1 100644 | |
--- a/test/mjsunit/test-http-server.js | |
+++ b/test/mjsunit/test-http-server.js | |
@@ -33,15 +33,19 @@ http.createServer(function (req, res) { | |
if (req.id == 3) { | |
assert.equal("bar", req.headers['x-x']); | |
+ } | |
+ | |
+ if (req.id == 4) { | |
+ assert.deepEqual(["one", "two"], req.headers["x-x"]); | |
this.close(); | |
- //puts("server closed"); | |
+ // puts("server closed"); | |
} | |
setTimeout(function () { | |
res.sendHeader(200, {"Content-Type": "text/plain"}); | |
res.sendBody(url.parse(req.url).pathname); | |
res.finish(); | |
- }, 1); | |
+ },1); | |
}).listen(port); | |
@@ -65,9 +69,14 @@ c.addListener("receive", function (chunk) { | |
if (requests_sent == 2) { | |
c.send("GET / HTTP/1.1\r\nX-X: foo\r\n\r\n" | |
+"GET / HTTP/1.1\r\nX-X: bar\r\n\r\n"); | |
+ requests_sent += 2; | |
+ } | |
+ | |
+ if (requests_sent == 4) { | |
+ c.send("GET / HTTP/1.1\r\nx-X: one\r\nX-x: two\r\n\r\n"); | |
+ requests_sent += 1; | |
c.close(); | |
assert.equal(c.readyState, "readOnly"); | |
- requests_sent += 2; | |
} | |
}); | |
@@ -81,8 +90,8 @@ c.addListener("close", function () { | |
}); | |
process.addListener("exit", function () { | |
- assert.equal(4, request_number); | |
- assert.equal(4, requests_sent); | |
+ assert.equal(5, request_number); | |
+ assert.equal(5, requests_sent); | |
var hello = new RegExp("/hello"); | |
assert.equal(true, hello.exec(server_response) != null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment