@@ -387,16 +387,6 @@ class Http {
387
387
Http (this ._cookies, this ._location, this ._rewriter, this ._backend,
388
388
this .defaults, this ._interceptors);
389
389
390
- /**
391
- * DEPRECATED
392
- */
393
- async .Future <String > getString (String url, {bool withCredentials,
394
- void onProgress (dom.ProgressEvent e), Cache cache}) =>
395
- request (url,
396
- withCredentials: withCredentials,
397
- onProgress: onProgress,
398
- cache: cache).then ((HttpResponse xhr) => xhr.responseText);
399
-
400
390
/**
401
391
* Parse a [requestUrl] and determine whether this is a same-origin request as
402
392
* the application document.
@@ -442,6 +432,7 @@ class Http {
442
432
throw ['timeout not implemented' ];
443
433
}
444
434
435
+ url = _rewriter (url);
445
436
method = method.toUpperCase ();
446
437
447
438
if (headers == null ) headers = {};
@@ -461,8 +452,7 @@ class Http {
461
452
});
462
453
463
454
var serverRequest = (HttpResponseConfig config) {
464
- assert (config.data == null || config.data is String ||
465
- config.data is dom.File );
455
+ assert (config.data == null || config.data is String || config.data is dom.File );
466
456
467
457
// Strip content-type if data is undefined
468
458
if (config.data == null ) {
@@ -471,12 +461,45 @@ class Http {
471
461
.forEach ((h) => headers.remove (h));
472
462
}
473
463
474
- return request (null ,
475
- config: config,
476
- method: method,
477
- sendData: config.data,
478
- requestHeaders: config.headers,
479
- cache: cache);
464
+ url = _buildUrl (config.url, config.params);
465
+
466
+ if (cache == false ) {
467
+ cache = null ;
468
+ } else if (cache == null ) {
469
+ cache = defaults.cache;
470
+ }
471
+
472
+ // We return a pending request only if caching is enabled.
473
+ if (cache != null && _pendingRequests.containsKey (url)) {
474
+ return _pendingRequests[url];
475
+ }
476
+ var cachedResponse = (cache != null && method == 'GET' ) ? cache.get (url) : null ;
477
+ if (cachedResponse != null ) {
478
+ return new async .Future .value (new HttpResponse .copy (cachedResponse));
479
+ }
480
+
481
+ var result = _backend.request (url,
482
+ method: method,
483
+ requestHeaders: config.headers,
484
+ sendData: config.data).then ((dom.HttpRequest value) {
485
+ // TODO: Uncomment after apps migrate off of this class.
486
+ // assert(value.status >= 200 && value.status < 300);
487
+
488
+ var response = new HttpResponse (value.status, value.responseText,
489
+ parseHeaders (value), config);
490
+
491
+ if (cache != null ) cache.put (url, response);
492
+ _pendingRequests.remove (url);
493
+ return response;
494
+ }, onError: (error) {
495
+ if (error is ! dom.ProgressEvent ) throw error;
496
+ dom.ProgressEvent event = error;
497
+ _pendingRequests.remove (url);
498
+ dom.HttpRequest request = event.currentTarget;
499
+ return new async .Future .error (
500
+ new HttpResponse (request.status, request.response, parseHeaders (request), config));
501
+ });
502
+ return _pendingRequests[url] = result;
480
503
};
481
504
482
505
var chain = [[serverRequest, null ]];
@@ -632,81 +655,13 @@ class Http {
632
655
});
633
656
return parsed;
634
657
}
635
-
636
658
/**
637
659
* Returns an [Iterable] of [Future] [HttpResponse] s for the requests
638
660
* that the [Http] service is currently waiting for.
639
661
*/
640
662
Iterable <async.Future <HttpResponse > > get pendingRequests =>
641
663
_pendingRequests.values;
642
664
643
- /**
644
- * DEPRECATED
645
- */
646
- async .Future <HttpResponse > request (String rawUrl,
647
- { HttpResponseConfig config,
648
- String method: 'GET' ,
649
- bool withCredentials: false ,
650
- String responseType,
651
- String mimeType,
652
- Map <String , String > requestHeaders,
653
- sendData,
654
- void onProgress (dom.ProgressEvent e),
655
- /*Cache<String, HttpResponse> or false*/ cache }) {
656
- String url;
657
-
658
- if (config == null ) {
659
- url = _rewriter (rawUrl);
660
- config = new HttpResponseConfig (url: url);
661
- } else {
662
- url = _buildUrl (config.url, config.params);
663
- }
664
-
665
- if (cache == false ) {
666
- cache = null ;
667
- } else if (cache == null ) {
668
- cache = defaults.cache;
669
- }
670
- // We return a pending request only if caching is enabled.
671
- if (cache != null && _pendingRequests.containsKey (url)) {
672
- return _pendingRequests[url];
673
- }
674
- var cachedResponse = (cache != null && method == 'GET' )
675
- ? cache.get (url)
676
- : null ;
677
- if (cachedResponse != null ) {
678
- return new async .Future .value (new HttpResponse .copy (cachedResponse));
679
- }
680
-
681
- var result = _backend.request (url,
682
- method: method,
683
- withCredentials: withCredentials,
684
- responseType: responseType,
685
- mimeType: mimeType,
686
- requestHeaders: requestHeaders,
687
- sendData: sendData,
688
- onProgress: onProgress).then ((dom.HttpRequest value) {
689
- // TODO: Uncomment after apps migrate off of this class.
690
- // assert(value.status >= 200 && value.status < 300);
691
-
692
- var response = new HttpResponse (value.status, value.responseText,
693
- parseHeaders (value), config);
694
-
695
- if (cache != null ) cache.put (url, response);
696
- _pendingRequests.remove (url);
697
- return response;
698
- }, onError: (error) {
699
- if (error is ! dom.ProgressEvent ) throw error;
700
- dom.ProgressEvent event = error;
701
- _pendingRequests.remove (url);
702
- dom.HttpRequest request = event.currentTarget;
703
- return new async .Future .error (
704
- new HttpResponse (request.status, request.response,
705
- parseHeaders (request), config));
706
- });
707
- return _pendingRequests[url] = result;
708
- }
709
-
710
665
_buildUrl (String url, Map <String , dynamic > params) {
711
666
if (params == null ) return url;
712
667
var parts = [];
0 commit comments