File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change 11var http = module . exports ;
22var EventEmitter = require ( 'events' ) . EventEmitter ;
33var Request = require ( './lib/request' ) ;
4+ var url = require ( 'url' )
45
56http . request = function ( params , cb ) {
7+ if ( typeof params === 'string' ) {
8+ params = url . parse ( params )
9+ }
610 if ( ! params ) params = { } ;
711 if ( ! params . host && ! params . port ) {
812 params . port = parseInt ( window . location . port , 10 ) ;
913 }
1014 if ( ! params . host && params . hostname ) {
1115 params . host = params . hostname ;
1216 }
13-
17+
1418 if ( ! params . scheme ) params . scheme = window . location . protocol . split ( ':' ) [ 0 ] ;
1519 if ( ! params . host ) {
1620 params . host = window . location . hostname || window . location . host ;
@@ -22,7 +26,7 @@ http.request = function (params, cb) {
2226 params . host = params . host . split ( ':' ) [ 0 ] ;
2327 }
2428 if ( ! params . port ) params . port = params . scheme == 'https' ? 443 : 80 ;
25-
29+
2630 var req = new Request ( new xhrHttp , params ) ;
2731 if ( cb ) req . on ( 'response' , cb ) ;
2832 return req ;
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ test('Test simple url string', function(t) {
2727
2828
2929test ( 'Test full url object' , function ( t ) {
30- var url = {
30+ var url = {
3131 host : "localhost:8081" ,
3232 hostname : "localhost" ,
3333 href : "http://localhost:8081/api/foo?bar=baz" ,
@@ -46,4 +46,14 @@ test('Test full url object', function(t) {
4646 t . equal ( request . uri , 'http://localhost:8081/api/foo?bar=baz' , 'Url should be correct' ) ;
4747 t . end ( ) ;
4848
49- } ) ;
49+ } ) ;
50+
51+
52+ test ( 'Test string as parameters' , function ( t ) {
53+ var url = '/api/foo' ;
54+ var request = http . get ( url , noop ) ;
55+
56+ t . equal ( request . uri , 'http://localhost:8081/api/foo' , 'Url should be correct' ) ;
57+ t . end ( ) ;
58+
59+ } )
You can’t perform that action at this time.
0 commit comments