Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix #1531
From 1c076172f7b72d06c0831679da997e8e18accfdc Mon Sep 17 00:00:00 2001
From: koichik <koichik@improvement.jp>
Date: Mon, 15 Aug 2011 17:33:34 +0900
Subject: [PATCH] https: Fix https2 breaks compatibility with https1
Fixes #1531.
---
lib/http2.js | 8 ++++++--
lib/https2.js | 16 +++++++++++++++-
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/lib/http2.js b/lib/http2.js
index 8a5d83a..331a007 100644
--- a/lib/http2.js
+++ b/lib/http2.js
@@ -1028,7 +1028,7 @@ function ClientRequest(options, cb) {
if (self.socketPath) {
self._last = true;
self.shouldKeepAlive = false;
- self.onSocket(net.createConnection(self.socketPath));
+ self.onSocket(self._createConnection(self.socketPath));
} else if (self.agent) {
// If there is an agent we should default to Connection:keep-alive.
self._last = false;
@@ -1038,7 +1038,7 @@ function ClientRequest(options, cb) {
// No agent, default to Connection:close.
self._last = true;
self.shouldKeepAlive = false;
- self.onSocket(net.createConnection(options.port, options.host));
+ self.onSocket(self._createConnection(options.port, options.host));
}
self._deferToConnect(null, null, function () {
@@ -1050,6 +1050,10 @@ util.inherits(ClientRequest, OutgoingMessage);
exports.ClientRequest = ClientRequest;
+ClientRequest.prototype._createConnection = function(port, host) {
+ return net.createConnection(port, host);
+};
+
ClientRequest.prototype._implicitHeader = function() {
this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n', this._renderHeaders());
};
diff --git a/lib/https2.js b/lib/https2.js
index 02f3289..c8d01dc 100644
--- a/lib/https2.js
+++ b/lib/https2.js
@@ -49,6 +49,19 @@ exports.createServer = function(opts, requestListener) {
};
+// HTTPS client requests.
+
+function HttpsClientRequest(options, cb) {
+ http.ClientRequest.call(this, options, cb);
+ this.options = options;
+}
+inherits(HttpsClientRequest, http.ClientRequest);
+
+HttpsClientRequest.prototype._createConnection = function(port, host) {
+ return tls.connect(port, host, this.options);
+};
+
+
// HTTPS agents.
function Agent(options) {
@@ -70,7 +83,7 @@ exports.request = function(options, cb) {
options.agent = globalAgent;
}
options.defaultPort = options.defaultPort || 443;
- return http.request(options, cb);
+ return new HttpsClientRequest(options, cb);
};
exports.get = function(options, cb) {
@@ -79,3 +92,4 @@ exports.get = function(options, cb) {
req.end();
return req;
};
+
--
1.7.4.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment