File tree Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Expand file tree Collapse file tree 3 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -14,8 +14,15 @@ http.request = function (params, cb) {
14
14
if ( ! params . host && params . hostname ) {
15
15
params . host = params . hostname ;
16
16
}
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
+
19
26
if ( ! params . host ) {
20
27
params . host = window . location . hostname || window . location . host ;
21
28
}
@@ -25,7 +32,7 @@ http.request = function (params, cb) {
25
32
}
26
33
params . host = params . host . split ( ':' ) [ 0 ] ;
27
34
}
28
- if ( ! params . port ) params . port = params . scheme == 'https' ? 443 : 80 ;
35
+ if ( ! params . port ) params . port = params . protocol == 'https: ' ? 443 : 80 ;
29
36
30
37
var req = new Request ( new xhrHttp , params ) ;
31
38
if ( cb ) req . on ( 'response' , cb ) ;
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ var Request = module.exports = function (xhr, params) {
9
9
self . xhr = xhr ;
10
10
self . body = [ ] ;
11
11
12
- self . uri = ( params . scheme || 'http' ) + ': //'
12
+ self . uri = ( params . protocol || 'http: ' ) + '//'
13
13
+ params . host
14
14
+ ( params . port ? ':' + params . port : '' )
15
15
+ ( params . path || '/' )
Original file line number Diff line number Diff line change @@ -48,6 +48,20 @@ test('Test full url object', function(t) {
48
48
49
49
} ) ;
50
50
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
+ } ) ;
51
65
52
66
test ( 'Test string as parameters' , function ( t ) {
53
67
var url = '/api/foo' ;
You can’t perform that action at this time.
0 commit comments