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