Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of html; | 5 part of html; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A utility for retrieving data from a URL. | 8 * A utility for retrieving data from a URL. |
| 9 * | 9 * |
| 10 * HttpRequest can be used to obtain data from http, ftp, and file | 10 * HttpRequest can be used to obtain data from http, ftp, and file |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildca rd (*). | 54 * * The `Access-Control-Allow-Origin` header of `url` cannot contain a wildca rd (*). |
| 55 * * The `Access-Control-Allow-Credentials` header of `url` must be set to tru e. | 55 * * The `Access-Control-Allow-Credentials` header of `url` must be set to tru e. |
| 56 * * If `Access-Control-Expose-Headers` has not been set to true, only a subse t of all the response headers will be returned when calling [getAllRequestHeader s]. | 56 * * If `Access-Control-Expose-Headers` has not been set to true, only a subse t of all the response headers will be returned when calling [getAllRequestHeader s]. |
| 57 * | 57 * |
| 58 * See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access _authentication). | 58 * See also: [authorization headers](http://en.wikipedia.org/wiki/Basic_access _authentication). |
| 59 */ | 59 */ |
| 60 factory $CLASSNAME.getWithCredentials(String url, | 60 factory $CLASSNAME.getWithCredentials(String url, |
| 61 onComplete($CLASSNAME request)) => | 61 onComplete($CLASSNAME request)) => |
| 62 _HttpRequestUtils.get(url, onComplete, true); | 62 _HttpRequestUtils.get(url, onComplete, true); |
| 63 | 63 |
| 64 | |
| 65 /** | |
| 66 * Creates a URL get request for the specified `url`. | |
| 67 * | |
| 68 * The server response must be a `text/` mime type for this request to | |
| 69 * succeed. | |
|
Emily Fortuna
2013/01/31 01:04:15
might say in the docs how this is different from t
blois
2013/01/31 18:58:12
Done.
| |
| 70 */ | |
| 71 static Future<String> getString(String url, | |
| 72 {bool withCredentials}) { | |
| 73 return request(url, withCredentials: withCredentials).then( | |
| 74 (xhr) { | |
|
Jennifer Messerly
2013/01/31 04:12:17
maybe format this as:
(xhr) => xhr.responseText
?
blois
2013/01/31 18:58:12
Done.
| |
| 75 return xhr.responseText; | |
| 76 }); | |
| 77 } | |
| 78 | |
| 79 /** | |
| 80 * Creates a URL request for the specified `url`. | |
|
Jennifer Messerly
2013/01/31 04:12:17
[url] ?
blois
2013/01/31 18:58:12
Done. Was mostly just following formatting from ex
| |
| 81 * | |
| 82 * By default this will do an HTTP GET request, this can be overridden with | |
| 83 * [method]. | |
| 84 * | |
| 85 * The Future is completed when the response is available. | |
| 86 */ | |
|
Emily Fortuna
2013/01/31 01:04:15
since this method replaces the functionality of th
Jennifer Messerly
2013/01/31 04:12:17
I was wondering that too. They take callbacks inst
blois
2013/01/31 18:58:12
The primary benefit of the factories is that you c
| |
| 87 static Future<HttpRequest> request(String url, | |
| 88 {String method, bool withCredentials, String responseType, sendData}) { | |
| 89 var completer = new Completer<String>(); | |
| 90 | |
| 91 var xhr = new HttpRequest(); | |
| 92 if (method == null) { | |
| 93 method = 'GET'; | |
| 94 } | |
| 95 xhr.open(method, url, true); | |
| 96 | |
| 97 if (withCredentials != null) { | |
| 98 xhr.withCredentials = withCredentials; | |
| 99 } | |
| 100 | |
| 101 if (responseType != null) { | |
| 102 xhr.responseType = responseType; | |
| 103 } | |
| 104 | |
| 105 xhr.onLoad.listen((e) { | |
| 106 if (xhr.status >= 200 && xhr.status < 300 || | |
| 107 xhr.status == 304 ) { | |
| 108 completer.complete(xhr); | |
| 109 } else { | |
| 110 completer.completeError(e); | |
| 111 } | |
| 112 }); | |
| 113 | |
| 114 xhr.onError.listen((e) { | |
| 115 completer.completeError(e); | |
| 116 }); | |
| 117 | |
| 118 if (sendData != null) { | |
| 119 xhr.send(sendData); | |
| 120 } else { | |
| 121 xhr.send(); | |
| 122 } | |
| 123 | |
| 124 return completer.future; | |
| 125 } | |
| 126 | |
| 64 $!MEMBERS | 127 $!MEMBERS |
| 65 } | 128 } |
| OLD | NEW |