Skip to content

Commit

Permalink
Support for https. Requires pending patch in node core for consistent…
Browse files Browse the repository at this point in the history
… Agent API.
  • Loading branch information
mikeal committed Feb 5, 2011
1 parent 9121c47 commit 9ec3490
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var Request = function (options) {
util.inherits(Request, stream.Stream);
Request.prototype.getAgent = function (host, port) {
if (!this.pool[host+':'+port]) {
this.pool[host+':'+port] = new http.Agent(host, port);
this.pool[host+':'+port] = new this.httpModule.Agent({host:host, port:port});
}
return this.pool[host+':'+port];
}
Expand Down Expand Up @@ -159,6 +159,9 @@ Request.prototype.request = function () {
}
}

options.httpModule = {http:http, https:https}[options.proxy ? options.proxy.prototocl : options.uri.protocol]
if (!options.httpModule) throw new Error("Invalid protocol");

options.agent = options.getAgent(options.host, options.port);
if (options.maxSockets) {
options.agent.maxSockets = options.maxSockets;
Expand All @@ -167,7 +170,7 @@ Request.prototype.request = function () {
options.agent.maxSockets = options.pool.maxSockets;
}

options.req = http.request(options, function (response) {
options.req = options.httpModule.request(options, function (response) {
if (setHost) delete options.headers.host;
response.on("end", function () {
options.req.removeListener("error", clientErrorHandler);
Expand Down

0 comments on commit 9ec3490

Please sign in to comment.