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) {
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 ) ;
Original file line number Diff line number Diff 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 || '/' )
Original file line number Diff line number Diff 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
5266test ( 'Test string as parameters' , function ( t ) {
5367 var url = '/api/foo' ;
You can’t perform that action at this time.
0 commit comments