Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Unified Diff: third_party/pkg/angular/lib/core_dom/http.dart

Issue 257423008: Update all Angular libs (run update_all.sh). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/pkg/angular/lib/core_dom/http.dart
diff --git a/third_party/pkg/angular/lib/core_dom/http.dart b/third_party/pkg/angular/lib/core_dom/http.dart
index 15f44dbc88efa9847197f1954357c456c82020a3..fdae907e81eddab29e309709f4e4158fae903c3b 100644
--- a/third_party/pkg/angular/lib/core_dom/http.dart
+++ b/third_party/pkg/angular/lib/core_dom/http.dart
@@ -1,6 +1,6 @@
-part of angular.core.dom;
+part of angular.core.dom_internal;
-@NgInjectableService()
+@Injectable()
class UrlRewriter {
String call(url) => url;
}
@@ -14,7 +14,7 @@ class UrlRewriter {
* During testing this implementation is swapped with [MockHttpBackend] which
* can be trained with responses.
*/
-@NgInjectableService()
+@Injectable()
class HttpBackend {
/**
* Wrapper around dart:html's [HttpRequest.request]
@@ -29,7 +29,7 @@ class HttpBackend {
sendData: sendData, onProgress: onProgress);
}
-@NgInjectableService()
+@Injectable()
class LocationWrapper {
get location => dom.window.location;
}
@@ -95,7 +95,7 @@ class DefaultTransformDataHttpInterceptor implements HttpInterceptor {
/**
* A list of [HttpInterceptor]s.
*/
-@NgInjectableService()
+@Injectable()
class HttpInterceptors {
List<HttpInterceptor> _interceptors =
[new DefaultTransformDataHttpInterceptor()];
@@ -234,7 +234,7 @@ class HttpResponse {
/**
* Default header configuration.
*/
-@NgInjectableService()
+@Injectable()
class HttpDefaultHeaders {
static var _defaultContentType = 'application/json;charset=utf-8';
var _headers = {
@@ -280,7 +280,7 @@ class HttpDefaultHeaders {
* The default implementation provides headers which the
* Angular team believes to be useful.
*/
-@NgInjectableService()
+@Injectable()
class HttpDefaults {
/**
* The [HttpDefaultHeaders] object used by [Http] to add default headers
@@ -367,7 +367,7 @@ class HttpDefaults {
*
* NOTE: < not yet documented >
*/
-@NgInjectableService()
+@Injectable()
class Http {
var _pendingRequests = <String, async.Future<HttpResponse>>{};
BrowserCookies _cookies;
@@ -388,16 +388,6 @@ class Http {
this.defaults, this._interceptors);
/**
- * DEPRECATED
- */
- async.Future<String> getString(String url, {bool withCredentials,
- void onProgress(dom.ProgressEvent e), Cache cache}) =>
- request(url,
- withCredentials: withCredentials,
- onProgress: onProgress,
- cache: cache).then((HttpResponse xhr) => xhr.responseText);
-
- /**
* Parse a [requestUrl] and determine whether this is a same-origin request as
* the application document.
*/
@@ -431,7 +421,7 @@ class Http {
String method,
data,
Map<String, dynamic> params,
- Map<String, String> headers,
+ Map<String, dynamic> headers,
xsrfHeaderName,
xsrfCookieName,
interceptors,
@@ -442,6 +432,7 @@ class Http {
throw ['timeout not implemented'];
}
+ url = _rewriter(url);
method = method.toUpperCase();
if (headers == null) headers = {};
@@ -461,8 +452,7 @@ class Http {
});
var serverRequest = (HttpResponseConfig config) {
- assert(config.data == null || config.data is String ||
- config.data is dom.File);
+ assert(config.data == null || config.data is String || config.data is dom.File);
// Strip content-type if data is undefined
if (config.data == null) {
@@ -471,12 +461,45 @@ class Http {
.forEach((h) => headers.remove(h));
}
- return request(null,
- config: config,
- method: method,
- sendData: config.data,
- requestHeaders: config.headers,
- cache: cache);
+ url = _buildUrl(config.url, config.params);
+
+ if (cache == false) {
+ cache = null;
+ } else if (cache == null) {
+ cache = defaults.cache;
+ }
+
+ // We return a pending request only if caching is enabled.
+ if (cache != null && _pendingRequests.containsKey(url)) {
+ return _pendingRequests[url];
+ }
+ var cachedResponse = (cache != null && method == 'GET') ? cache.get(url) : null;
+ if (cachedResponse != null) {
+ return new async.Future.value(new HttpResponse.copy(cachedResponse));
+ }
+
+ var result = _backend.request(url,
+ method: method,
+ requestHeaders: config.headers,
+ sendData: config.data).then((dom.HttpRequest value) {
+ // TODO: Uncomment after apps migrate off of this class.
+ // assert(value.status >= 200 && value.status < 300);
+
+ var response = new HttpResponse(value.status, value.responseText,
+ parseHeaders(value), config);
+
+ if (cache != null) cache.put(url, response);
+ _pendingRequests.remove(url);
+ return response;
+ }, onError: (error) {
+ if (error is! dom.ProgressEvent) throw error;
+ dom.ProgressEvent event = error;
+ _pendingRequests.remove(url);
+ dom.HttpRequest request = event.currentTarget;
+ return new async.Future.error(
+ new HttpResponse(request.status, request.response, parseHeaders(request), config));
+ });
+ return _pendingRequests[url] = result;
};
var chain = [[serverRequest, null]];
@@ -632,7 +655,6 @@ class Http {
});
return parsed;
}
-
/**
* Returns an [Iterable] of [Future] [HttpResponse]s for the requests
* that the [Http] service is currently waiting for.
@@ -640,73 +662,6 @@ class Http {
Iterable<async.Future<HttpResponse> > get pendingRequests =>
_pendingRequests.values;
- /**
- * DEPRECATED
- */
- async.Future<HttpResponse> request(String rawUrl,
- { HttpResponseConfig config,
- String method: 'GET',
- bool withCredentials: false,
- String responseType,
- String mimeType,
- Map<String, String> requestHeaders,
- sendData,
- void onProgress(dom.ProgressEvent e),
- /*Cache<String, HttpResponse> or false*/ cache }) {
- String url;
-
- if (config == null) {
- url = _rewriter(rawUrl);
- config = new HttpResponseConfig(url: url);
- } else {
- url = _buildUrl(config.url, config.params);
- }
-
- if (cache == false) {
- cache = null;
- } else if (cache == null) {
- cache = defaults.cache;
- }
- // We return a pending request only if caching is enabled.
- if (cache != null && _pendingRequests.containsKey(url)) {
- return _pendingRequests[url];
- }
- var cachedResponse = (cache != null && method == 'GET')
- ? cache.get(url)
- : null;
- if (cachedResponse != null) {
- return new async.Future.value(new HttpResponse.copy(cachedResponse));
- }
-
- var result = _backend.request(url,
- method: method,
- withCredentials: withCredentials,
- responseType: responseType,
- mimeType: mimeType,
- requestHeaders: requestHeaders,
- sendData: sendData,
- onProgress: onProgress).then((dom.HttpRequest value) {
- // TODO: Uncomment after apps migrate off of this class.
- // assert(value.status >= 200 && value.status < 300);
-
- var response = new HttpResponse(value.status, value.responseText,
- parseHeaders(value), config);
-
- if (cache != null) cache.put(url, response);
- _pendingRequests.remove(url);
- return response;
- }, onError: (error) {
- if (error is! dom.ProgressEvent) throw error;
- dom.ProgressEvent event = error;
- _pendingRequests.remove(url);
- dom.HttpRequest request = event.currentTarget;
- return new async.Future.error(
- new HttpResponse(request.status, request.response,
- parseHeaders(request), config));
- });
- return _pendingRequests[url] = result;
- }
-
_buildUrl(String url, Map<String, dynamic> params) {
if (params == null) return url;
var parts = [];
« no previous file with comments | « third_party/pkg/angular/lib/core_dom/event_handler.dart ('k') | third_party/pkg/angular/lib/core_dom/module.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698