From c9f71a807c106fd5390e35054445a3f3b8111931 Mon Sep 17 00:00:00 2001 From: Rhys Jones Date: Mon, 12 Apr 2010 18:57:22 +0100 Subject: [PATCH] Added https support --- lib/http.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/http.js b/lib/http.js index 554f047..8e85fd5 100644 --- a/lib/http.js +++ b/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); -- 2.7.4