|
|
@ -571,6 +571,17 @@ function Client ( ) { |
|
|
|
}; |
|
|
|
|
|
|
|
self.addListener("connect", function () { |
|
|
|
if (this.https) { |
|
|
|
this.setSecure(this.credentials); |
|
|
|
} else { |
|
|
|
parser.reinitialize('response'); |
|
|
|
debug('requests: ' + sys.inspect(requests)); |
|
|
|
currentRequest = requests.shift() |
|
|
|
currentRequest.flush(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
self.addListener("secure", function () { |
|
|
|
parser.reinitialize('response'); |
|
|
|
debug('requests: ' + sys.inspect(requests)); |
|
|
|
currentRequest = requests.shift() |
|
|
@ -613,13 +624,18 @@ sys.inherits(Client, net.Stream); |
|
|
|
|
|
|
|
exports.Client = Client; |
|
|
|
|
|
|
|
exports.createClient = function (port, host) { |
|
|
|
exports.createClient = function (port, host, https, credentials) { |
|
|
|
var c = new Client; |
|
|
|
c.port = port; |
|
|
|
c.host = host; |
|
|
|
c.https = https; |
|
|
|
c.credentials = credentials; |
|
|
|
return c; |
|
|
|
} |
|
|
|
|
|
|
|
exports.createCredentials = function (credentials) { |
|
|
|
return net.createCredentials(credentials); |
|
|
|
} |
|
|
|
|
|
|
|
Client.prototype.get = function () { |
|
|
|
throw new Error("client.get(...) is now client.request('GET', ...)"); |
|
|
@ -678,7 +694,7 @@ exports.cat = function (url, encoding_, headers_) { |
|
|
|
} |
|
|
|
|
|
|
|
var url = require("url").parse(url); |
|
|
|
|
|
|
|
|
|
|
|
var hasHost = false; |
|
|
|
for (var i in headers) { |
|
|
|
if (i.toLowerCase() === "host") { |
|
|
@ -693,6 +709,10 @@ exports.cat = function (url, encoding_, headers_) { |
|
|
|
var client = exports.createClient(url.port || 80, url.hostname); |
|
|
|
var req = client.request((url.pathname || "/")+(url.search || "")+(url.hash || ""), headers); |
|
|
|
|
|
|
|
if (url.protocol=="https:") { |
|
|
|
client.https = true; |
|
|
|
} |
|
|
|
|
|
|
|
req.addListener('response', function (res) { |
|
|
|
if (res.statusCode < 200 || res.statusCode >= 300) { |
|
|
|
if (callback) callback(res.statusCode); |
|
|
|