@@ -3,17 +3,26 @@ part of angular;
3
3
// NOTE(deboer): This should be a generic utility class, but lets make sure
4
4
// it works in this case first!
5
5
class HttpFutures {
6
- value (x) => new async .Future .value (x);
6
+ async . Future value (x) => new async .Future .value (x);
7
7
}
8
8
9
9
class UrlRewriter {
10
10
String call (url) => url;
11
11
}
12
12
13
13
class HttpBackend {
14
- getString (String url, {bool withCredentials, void onProgress (dom.ProgressEvent e)}) {
15
- return dom.HttpRequest .getString (url, withCredentials: withCredentials, onProgress: onProgress);
16
- }
14
+ async .Future request (String url,
15
+ {String method, bool withCredentials, String responseType,
16
+ String mimeType, Map <String , String > requestHeaders, sendData,
17
+ void onProgress (dom.ProgressEvent e)}) =>
18
+ dom.HttpRequest .request (url,
19
+ method: method,
20
+ withCredentials: withCredentials,
21
+ responseType: responseType,
22
+ mimeType: mimeType,
23
+ requestHeaders: requestHeaders,
24
+ sendData: sendData,
25
+ onProgress: onProgress);
17
26
}
18
27
19
28
class Http {
@@ -24,7 +33,22 @@ class Http {
24
33
25
34
Http (UrlRewriter this .rewriter, HttpBackend this .backend, HttpFutures this .futures);
26
35
27
- async .Future <String > getString (String rawUrl, {bool withCredentials, void onProgress (dom.ProgressEvent e), Cache cache}) {
36
+ async .Future <String > getString (String url,
37
+ {bool withCredentials, void onProgress (ProgressEvent e), Cache cache}) {
38
+ return request (url,
39
+ withCredentials: withCredentials,
40
+ onProgress: onProgress,
41
+ cache: cache).then ((xhr) => xhr.responseText);
42
+ }
43
+
44
+ // TODO(deboer): The cache is keyed on the url only. It should be keyed on
45
+ // (url, method, mimeType, requestHeaders, ...)
46
+ // Better yet, we should be using a HTTP standard cache.
47
+ async .Future request (String rawUrl,
48
+ {String method, bool withCredentials, String responseType,
49
+ String mimeType, Map <String , String > requestHeaders, sendData,
50
+ void onProgress (dom.ProgressEvent e),
51
+ Cache cache}) {
28
52
String url = rewriter (rawUrl);
29
53
30
54
// We return a pending request only if caching is enabled.
@@ -35,7 +59,14 @@ class Http {
35
59
if (cachedValue != null ) {
36
60
return futures.value (cachedValue);
37
61
}
38
- var result = backend.getString (url, withCredentials: withCredentials, onProgress: onProgress).then ((value) {
62
+ var result = backend.request (url,
63
+ method: method,
64
+ withCredentials: withCredentials,
65
+ responseType: responseType,
66
+ mimeType: mimeType,
67
+ requestHeaders: requestHeaders,
68
+ sendData: sendData,
69
+ onProgress: onProgress).then ((value) {
39
70
if (cache != null ) {
40
71
cache.put (url, value);
41
72
}
@@ -49,3 +80,4 @@ class Http {
49
80
return result;
50
81
}
51
82
}
83
+
0 commit comments