|
@ -41,74 +41,6 @@ var STATUS_CODES = exports.STATUS_CODES = { |
|
|
505 : 'HTTP Version not supported' |
|
|
505 : 'HTTP Version not supported' |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
parseUri 1.2.1 |
|
|
|
|
|
(c) 2007 Steven Levithan <stevenlevithan.com> |
|
|
|
|
|
MIT License |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
function decode (s) { |
|
|
|
|
|
return decodeURIComponent(s.replace(/\+/g, ' ')); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
exports.parseUri = function (str) { |
|
|
|
|
|
var o = exports.parseUri.options, |
|
|
|
|
|
m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), |
|
|
|
|
|
uri = {}, |
|
|
|
|
|
i = 14; |
|
|
|
|
|
|
|
|
|
|
|
while (i--) uri[o.key[i]] = m[i] || ""; |
|
|
|
|
|
|
|
|
|
|
|
uri[o.q.name] = {}; |
|
|
|
|
|
uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { |
|
|
|
|
|
if ($1) { |
|
|
|
|
|
try { |
|
|
|
|
|
var key = decode($1); |
|
|
|
|
|
var val = decode($2); |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
uri[o.q.name][key] = val; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
uri.toString = function () { return str; }; |
|
|
|
|
|
|
|
|
|
|
|
for (i = o.key.length - 1; i >= 0; i--){ |
|
|
|
|
|
if (uri[o.key[i]] == "") delete uri[o.key[i]]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return uri; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
exports.parseUri.options = { |
|
|
|
|
|
strictMode: false, |
|
|
|
|
|
key: [ |
|
|
|
|
|
"source", |
|
|
|
|
|
"protocol", |
|
|
|
|
|
"authority", |
|
|
|
|
|
"userInfo", |
|
|
|
|
|
"user", |
|
|
|
|
|
"password", |
|
|
|
|
|
"host", |
|
|
|
|
|
"port", |
|
|
|
|
|
"relative", |
|
|
|
|
|
"path", |
|
|
|
|
|
"directory", |
|
|
|
|
|
"file", |
|
|
|
|
|
"query", |
|
|
|
|
|
"anchor" |
|
|
|
|
|
], |
|
|
|
|
|
q: { |
|
|
|
|
|
name: "params", |
|
|
|
|
|
parser: /(?:^|&)([^&=]*)=?([^&]*)/g |
|
|
|
|
|
}, |
|
|
|
|
|
parser: { |
|
|
|
|
|
strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, |
|
|
|
|
|
loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var connection_expression = /Connection/i; |
|
|
var connection_expression = /Connection/i; |
|
|
var transfer_encoding_expression = /Transfer-Encoding/i; |
|
|
var transfer_encoding_expression = /Transfer-Encoding/i; |
|
|
var close_expression = /close/i; |
|
|
var close_expression = /close/i; |
|
@ -142,6 +74,7 @@ function IncomingMessage (connection) { |
|
|
sys.inherits(IncomingMessage, process.EventEmitter); |
|
|
sys.inherits(IncomingMessage, process.EventEmitter); |
|
|
exports.IncomingMessage = IncomingMessage; |
|
|
exports.IncomingMessage = IncomingMessage; |
|
|
|
|
|
|
|
|
|
|
|
var decode = require("uri").decode; |
|
|
IncomingMessage.prototype._parseQueryString = function () { |
|
|
IncomingMessage.prototype._parseQueryString = function () { |
|
|
var parts = this.uri.queryString.split('&'); |
|
|
var parts = this.uri.queryString.split('&'); |
|
|
for (var j = 0; j < parts.length; j++) { |
|
|
for (var j = 0; j < parts.length; j++) { |
|
@ -631,13 +564,19 @@ exports.cat = function (url, encoding, headers) { |
|
|
|
|
|
|
|
|
encoding = encoding || "utf8"; |
|
|
encoding = encoding || "utf8"; |
|
|
|
|
|
|
|
|
var uri = exports.parseUri(url); |
|
|
var uri = require("uri").parse(url); |
|
|
headers = headers || {}; |
|
|
headers = headers || {}; |
|
|
if (!headers["Host"] && uri.host) { |
|
|
|
|
|
headers["Host"] = uri.host; |
|
|
var hasHost = false; |
|
|
|
|
|
for (var i in headers) if (i.toLowerCase() === "host") { |
|
|
|
|
|
hasHost = true; |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
if (!hasHost) { |
|
|
|
|
|
headers["Host"] = uri.domain; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var client = exports.createClient(uri.port || 80, uri.host); |
|
|
var client = exports.createClient(uri.port || 80, uri.domain); |
|
|
var req = client.request(uri.path || "/", headers); |
|
|
var req = client.request(uri.path || "/", headers); |
|
|
|
|
|
|
|
|
client.addListener("error", function () { |
|
|
client.addListener("error", function () { |
|
|