Skip to content

Commit 4e4aa4e

Browse files
author
James Halliday
committed
merged issues#28 the good parts, passing the test
1 parent b0049fe commit 4e4aa4e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@ http.request = function (params, cb) {
77
if (!params.host && !params.port) {
88
params.port = parseInt(window.location.port, 10);
99
}
10+
if (!params.host && params.hostname) {
11+
params.host = params.hostname;
12+
}
13+
1014
if (!params.scheme) params.scheme = window.location.protocol.split(':')[0];
11-
if (!params.host) params.host = window.location.hostname;
15+
if (!params.host) {
16+
params.host = window.location.hostname || window.location.host;
17+
}
18+
if (/:/.test(params.host)) {
19+
if (!params.port) {
20+
params.port = params.host.split(':')[1];
21+
}
22+
params.host = params.host.split(':')[0];
23+
}
1224
if (!params.port) params.port = params.scheme == 'https' ? 443 : 80;
1325

1426
var req = new Request(new xhrHttp, params);

lib/request.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ var Request = module.exports = function (xhr, params) {
1010
self.xhr = xhr;
1111
self.body = concatStream()
1212

13-
var uri = params.host
13+
self.uri = (params.scheme || 'http') + '://'
14+
+ params.host
1415
+ (params.port ? ':' + params.port : '')
1516
+ (params.path || '/')
1617
;
@@ -19,7 +20,7 @@ var Request = module.exports = function (xhr, params) {
1920

2021
xhr.open(
2122
params.method || 'GET',
22-
(params.scheme || 'http') + '://' + uri,
23+
self.uri,
2324
true
2425
);
2526

0 commit comments

Comments
 (0)