|
|
@ -267,29 +267,34 @@ OutgoingMessage.prototype.sendHeaderLines = function (firstLine, headers) { |
|
|
|
// in the case of response it is: "HTTP/1.1 200 OK\r\n"
|
|
|
|
var messageHeader = firstLine; |
|
|
|
var field, value; |
|
|
|
for (var i in headers) { |
|
|
|
if (headers[i] instanceof Array) { |
|
|
|
field = headers[i][0]; |
|
|
|
value = headers[i][1]; |
|
|
|
} else { |
|
|
|
if (!headers.hasOwnProperty(i)) continue; |
|
|
|
field = i; |
|
|
|
value = headers[i]; |
|
|
|
} |
|
|
|
|
|
|
|
messageHeader += field + ": " + value + CRLF; |
|
|
|
if (headers) { |
|
|
|
var keys = Object.keys(headers); |
|
|
|
var isArray = (headers instanceof Array); |
|
|
|
for (var i = 0, l = keys.length; i < l; i++) { |
|
|
|
var key = keys[i]; |
|
|
|
if (isArray) { |
|
|
|
field = headers[key][0]; |
|
|
|
value = headers[key][1]; |
|
|
|
} else { |
|
|
|
field = key; |
|
|
|
value = headers[key]; |
|
|
|
} |
|
|
|
|
|
|
|
messageHeader += field + ": " + value + CRLF; |
|
|
|
|
|
|
|
if (connectionExpression.test(field)) { |
|
|
|
sentConnectionHeader = true; |
|
|
|
if (closeExpression.test(value)) this.closeOnFinish = true; |
|
|
|
if (connectionExpression.test(field)) { |
|
|
|
sentConnectionHeader = true; |
|
|
|
if (closeExpression.test(value)) this.closeOnFinish = true; |
|
|
|
|
|
|
|
} else if (transferEncodingExpression.test(field)) { |
|
|
|
sentTransferEncodingHeader = true; |
|
|
|
if (chunkExpression.test(value)) this.chunkedEncoding = true; |
|
|
|
} else if (transferEncodingExpression.test(field)) { |
|
|
|
sentTransferEncodingHeader = true; |
|
|
|
if (chunkExpression.test(value)) this.chunkedEncoding = true; |
|
|
|
|
|
|
|
} else if (contentLengthExpression.test(field)) { |
|
|
|
sentContentLengthHeader = true; |
|
|
|
} else if (contentLengthExpression.test(field)) { |
|
|
|
sentContentLengthHeader = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -696,10 +701,21 @@ exports.cat = function (url, encoding_, headers_) { |
|
|
|
var url = require("url").parse(url); |
|
|
|
|
|
|
|
var hasHost = false; |
|
|
|
for (var i in headers) { |
|
|
|
if (i.toLowerCase() === "host") { |
|
|
|
hasHost = true; |
|
|
|
break; |
|
|
|
if (headers instanceof Array) { |
|
|
|
for (var i = 0, l = headers.length; i < l; i++) { |
|
|
|
if (headers[i][0].toLowerCase() === 'host') { |
|
|
|
hasHost = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (typeof headers === "Object") { |
|
|
|
var keys = Object.keys(headers); |
|
|
|
for (var i = 0, l = keys.length; i < l; i++) { |
|
|
|
var key = keys[i]; |
|
|
|
if (key.toLowerCase() == 'host') { |
|
|
|
hasHost = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (!hasHost) headers["Host"] = url.hostname; |
|
|
|