Skip to content

Commit 2fdbcd2

Browse files
committed
Prefer protocol to scheme
When using url.parse(), a protocol will be provided instead of scheme.
1 parent df11f4a commit 2fdbcd2

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ http.request = function (params, cb) {
1414
if (!params.host && params.hostname) {
1515
params.host = params.hostname;
1616
}
17-
17+
18+
if (params.protocol) {
19+
params.scheme = params.protocol.split(':')[0];
20+
}
21+
1822
if (!params.scheme) params.scheme = window.location.protocol.split(':')[0];
1923
if (!params.host) {
2024
params.host = window.location.hostname || window.location.host;

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)