@@ -25,6 +25,13 @@ class HttpBackend {
25
25
onProgress: onProgress);
26
26
}
27
27
28
+ class HttpResponse {
29
+ int status;
30
+ String responseText;
31
+ Map <String , String > headers;
32
+ HttpResponse ([this .status, this .responseText, this .headers]);
33
+ }
34
+
28
35
class Http {
29
36
Map <String , async.Future <String >> _pendingRequests = < String , async .Future <String >> {};
30
37
UrlRewriter rewriter;
@@ -38,17 +45,17 @@ class Http {
38
45
return request (url,
39
46
withCredentials: withCredentials,
40
47
onProgress: onProgress,
41
- cache: cache).then ((xhr) => xhr.responseText);
48
+ cache: cache).then ((HttpResponse xhr) => xhr.responseText);
42
49
}
43
50
44
51
// TODO(deboer): The cache is keyed on the url only. It should be keyed on
45
52
// (url, method, mimeType, requestHeaders, ...)
46
53
// Better yet, we should be using a HTTP standard cache.
47
- async .Future request (String rawUrl,
54
+ async .Future < HttpResponse > request (String rawUrl,
48
55
{String method, bool withCredentials, String responseType,
49
56
String mimeType, Map <String , String > requestHeaders, sendData,
50
57
void onProgress (dom.ProgressEvent e),
51
- Cache cache}) {
58
+ Cache < HttpResponse > cache}) {
52
59
String url = rewriter (rawUrl);
53
60
54
61
// We return a pending request only if caching is enabled.
@@ -67,11 +74,14 @@ class Http {
67
74
requestHeaders: requestHeaders,
68
75
sendData: sendData,
69
76
onProgress: onProgress).then ((value) {
77
+ // NOTE(deboer): Missing headers. Ask the Dart team for a sane API.
78
+ var response = new HttpResponse (value.status, value.responseText);
79
+
70
80
if (cache != null ) {
71
- cache.put (url, value );
81
+ cache.put (url, response );
72
82
}
73
83
_pendingRequests.remove (url);
74
- return value ;
84
+ return response ;
75
85
}, onError: (error) {
76
86
_pendingRequests.remove (url);
77
87
throw error;
0 commit comments