Skip to content

Commit 7826c6e

Browse files
author
James Halliday
committed
Merge pull request #64 from tschaub/protocol
Respect protocol
2 parents df11f4a + cf4f5a8 commit 7826c6e

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

index.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ http.request = function (params, cb) {
1414
if (!params.host && params.hostname) {
1515
params.host = params.hostname;
1616
}
17-
18-
if (!params.scheme) params.scheme = window.location.protocol.split(':')[0];
17+
18+
if (!params.protocol) {
19+
if (params.scheme) {
20+
params.protocol = params.scheme + ':';
21+
} else {
22+
params.protocol = window.location.protocol;
23+
}
24+
}
25+
1926
if (!params.host) {
2027
params.host = window.location.hostname || window.location.host;
2128
}
@@ -25,7 +32,7 @@ http.request = function (params, cb) {
2532
}
2633
params.host = params.host.split(':')[0];
2734
}
28-
if (!params.port) params.port = params.scheme == 'https' ? 443 : 80;
35+
if (!params.port) params.port = params.protocol == 'https:' ? 443 : 80;
2936

3037
var req = new Request(new xhrHttp, params);
3138
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 || '/')

test/request_url.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ test('Test full url object', function(t) {
4848

4949
});
5050

51+
test('Test alt protocol', function(t) {
52+
var params = {
53+
protocol: "foo:",
54+
hostname: "localhost",
55+
port: "3000",
56+
path: "/bar"
57+
};
58+
59+
var request = http.get(params, noop);
60+
61+
t.equal( request.uri, 'foo://localhost:3000/bar', 'Url should be correct');
62+
t.end();
63+
64+
});
5165

5266
test('Test string as parameters', function(t) {
5367
var url = '/api/foo';

0 commit comments

Comments
 (0)