diff --git a/index.js b/index.js index 5aeb875..5e84c4a 100644 --- a/index.js +++ b/index.js @@ -15,7 +15,11 @@ http.request = function (params, cb) { params.host = params.hostname; } - if (!params.scheme) params.scheme = window.location.protocol.split(':')[0]; + 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; } @@ -25,7 +29,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 || '/')