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 $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
6 | 6 |
7 /** | 7 /** |
8 * A client-side XHR request for getting data from a URL, | 8 * A client-side XHR request for getting data from a URL, |
9 * formally known as XMLHttpRequest. | 9 * formally known as XMLHttpRequest. |
10 * | 10 * |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 requestHeaders.forEach((header, value) { | 214 requestHeaders.forEach((header, value) { |
215 xhr.setRequestHeader(header, value); | 215 xhr.setRequestHeader(header, value); |
216 }); | 216 }); |
217 } | 217 } |
218 | 218 |
219 if (onProgress != null) { | 219 if (onProgress != null) { |
220 xhr.onProgress.listen(onProgress); | 220 xhr.onProgress.listen(onProgress); |
221 } | 221 } |
222 | 222 |
223 xhr.onLoad.listen((e) { | 223 xhr.onLoad.listen((e) { |
224 // Note: file:// URIs have status of 0. | 224 var accepted = xhr.status >= 200 && xhr.status < 300; |
225 if ((xhr.status >= 200 && xhr.status < 300) || | 225 var fileUri = xhr.status == 0; // file:// URIs have status of 0. |
226 xhr.status == 0 || xhr.status == 304) { | 226 var notModified = xhr.status == 304; |
| 227 // Redirect status is specified up to 307, but others have been used in |
| 228 // practice. Notably Google Drive uses 308 Resume Incomplete for |
| 229 // resumable uploads, and it's also been used as a redirect. The |
| 230 // redirect case will be handled by the browser before it gets to us, |
| 231 // so if we see it we should pass it through to the user. |
| 232 var unknownRedirect = xhr.status > 307 && xhr.status < 400; |
| 233 |
| 234 if (accepted || fileUri || notModified || unknownRedirect) { |
227 completer.complete(xhr); | 235 completer.complete(xhr); |
228 } else { | 236 } else { |
229 completer.completeError(e); | 237 completer.completeError(e); |
230 } | 238 } |
231 }); | 239 }); |
232 | 240 |
233 xhr.onError.listen(completer.completeError); | 241 xhr.onError.listen(completer.completeError); |
234 | 242 |
235 if (sendData != null) { | 243 if (sendData != null) { |
236 xhr.send(sendData); | 244 xhr.send(sendData); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 headers[key] = '${headers[key]}, $value'; | 379 headers[key] = '${headers[key]}, $value'; |
372 } else { | 380 } else { |
373 headers[key] = value; | 381 headers[key] = value; |
374 } | 382 } |
375 } | 383 } |
376 return headers; | 384 return headers; |
377 } | 385 } |
378 | 386 |
379 $!MEMBERS | 387 $!MEMBERS |
380 } | 388 } |
OLD | NEW |