Skip to content

Commit cf4f5a8

Browse files
committed
Only use scheme if no protocol is provided
1 parent 2fdbcd2 commit cf4f5a8

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ http.request = function (params, cb) {
1515
params.host = params.hostname;
1616
}
1717

18-
if (params.protocol) {
19-
params.scheme = params.protocol.split(':')[0];
18+
if (!params.protocol) {
19+
if (params.scheme) {
20+
params.protocol = params.scheme + ':';
21+
} else {
22+
params.protocol = window.location.protocol;
23+
}
2024
}
2125

22-
if (!params.scheme) params.scheme = window.location.protocol.split(':')[0];
2326
if (!params.host) {
2427
params.host = window.location.hostname || window.location.host;
2528
}
@@ -29,7 +32,7 @@ http.request = function (params, cb) {
2932
}
3033
params.host = params.host.split(':')[0];
3134
}
32-
if (!params.port) params.port = params.scheme == 'https' ? 443 : 80;
35+
if (!params.port) params.port = params.protocol == 'https:' ? 443 : 80;
3336

3437
var req = new Request(new xhrHttp, params);
3538
if (cb) req.on('response', cb);

lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var Request = module.exports = function (xhr, params) {
99
self.xhr = xhr;
1010
self.body = [];
1111

12-
self.uri = (params.scheme || 'http') + '://'
12+
self.uri = (params.protocol || 'http:') + '//'
1313
+ params.host
1414
+ (params.port ? ':' + params.port : '')
1515
+ (params.path || '/')

0 commit comments

Comments
 (0)