Browse Source

Added https support

v0.7.4-release
Rhys Jones 15 years ago
parent
commit
c9f71a807c
  1. 24
      lib/http.js

24
lib/http.js

@ -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);

Loading…
Cancel
Save