From b78830457d5a2961b38f552bab8280ecce0be79e Mon Sep 17 00:00:00 2001 From: Hendrik Cech Date: Sat, 15 Feb 2014 14:33:46 +1300 Subject: [PATCH 1/2] replace params.scheme with params.protocol --- index.js | 5 +++-- lib/request.js | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5aeb875..271a32c 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,8 @@ http.request = function (params, cb) { params.host = params.hostname; } - if (!params.scheme) params.scheme = window.location.protocol.split(':')[0]; + if(!params.protocol) params.protocol = window.location.protocol; + if (!params.host) { params.host = window.location.hostname || window.location.host; } @@ -25,7 +26,7 @@ http.request = function (params, cb) { } params.host = params.host.split(':')[0]; } - if (!params.port) params.port = params.scheme == 'https' ? 443 : 80; + if (!params.port) params.port = params.protocol == 'https:' ? 443 : 80; var req = new Request(new xhrHttp, params); if (cb) req.on('response', cb); diff --git a/lib/request.js b/lib/request.js index 0903640..5e03671 100644 --- a/lib/request.js +++ b/lib/request.js @@ -9,7 +9,7 @@ var Request = module.exports = function (xhr, params) { self.xhr = xhr; self.body = []; - self.uri = (params.scheme || 'http') + '://' + self.uri = (params.protocol || 'http:') + '//' + params.host + (params.port ? ':' + params.port : '') + (params.path || '/') From cff10e8e9ebf8699d5f0a8a7215de7e07ee0c9c6 Mon Sep 17 00:00:00 2001 From: Hendrik Cech Date: Mon, 17 Feb 2014 14:38:03 +1300 Subject: [PATCH 2/2] backwards support for params.scheme --- index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 271a32c..5e84c4a 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,10 @@ http.request = function (params, cb) { params.host = params.hostname; } - if(!params.protocol) params.protocol = window.location.protocol; + if (!params.protocol) { + params.protocol = params.scheme || window.location.protocol; + if (!/:$/.test(params.protocol)) params.protocol += ':'; + } if (!params.host) { params.host = window.location.hostname || window.location.host;