OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 dart.io; | 5 part of dart.io; |
6 | 6 |
7 class _HttpIncoming extends Stream<List<int>> { | 7 class _HttpIncoming extends Stream<List<int>> { |
8 final int _transferLength; | 8 final int _transferLength; |
9 final Completer _dataCompleter = new Completer(); | 9 final Completer _dataCompleter = new Completer(); |
10 Stream<List<int>> _stream; | 10 Stream<List<int>> _stream; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 String location = headers.value(HttpHeaders.LOCATION); | 209 String location = headers.value(HttpHeaders.LOCATION); |
210 if (location == null) { | 210 if (location == null) { |
211 throw new StateError("Response has no Location header for redirect"); | 211 throw new StateError("Response has no Location header for redirect"); |
212 } | 212 } |
213 url = Uri.parse(location); | 213 url = Uri.parse(location); |
214 } | 214 } |
215 if (followLoops != true) { | 215 if (followLoops != true) { |
216 for (var redirect in redirects) { | 216 for (var redirect in redirects) { |
217 if (redirect.location == url) { | 217 if (redirect.location == url) { |
218 return new Future.error( | 218 return new Future.error( |
219 new RedirectLoopException(redirects)); | 219 new RedirectException("Redirect loop detected", redirects)); |
220 } | 220 } |
221 } | 221 } |
222 } | 222 } |
223 return _httpClient._openUrlFromRequest(method, url, _httpRequest) | 223 return _httpClient._openUrlFromRequest(method, url, _httpRequest) |
224 .then((request) { | 224 .then((request) { |
225 request._responseRedirects.addAll(this.redirects); | 225 request._responseRedirects.addAll(this.redirects); |
226 request._responseRedirects.add(new _RedirectInfo(statusCode, | 226 request._responseRedirects.add(new _RedirectInfo(statusCode, |
227 method, | 227 method, |
228 url)); | 228 url)); |
229 return request.close(); | 229 return request.close(); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 onListen: () => _subscription.resume(), | 566 onListen: () => _subscription.resume(), |
567 onCancel: _cancel); | 567 onCancel: _cancel); |
568 _outbound._addStream(_controller.stream) | 568 _outbound._addStream(_controller.stream) |
569 .then((_) { | 569 .then((_) { |
570 _cancel(); | 570 _cancel(); |
571 _done(); | 571 _done(); |
572 _closeCompleter.complete(_outbound); | 572 _closeCompleter.complete(_outbound); |
573 }, | 573 }, |
574 onError: (error) { | 574 onError: (error) { |
575 _socketError = true; | 575 _socketError = true; |
576 if (error is SocketIOException && | 576 if (error is SocketException && |
577 _outbound is HttpResponse) { | 577 _outbound is HttpResponse) { |
578 _cancel(); | 578 _cancel(); |
579 _done(); | 579 _done(); |
580 _closeCompleter.complete(_outbound); | 580 _closeCompleter.complete(_outbound); |
581 } else { | 581 } else { |
582 if (!_done(error)) { | 582 if (!_done(error)) { |
583 _closeCompleter.completeError(error); | 583 _closeCompleter.completeError(error); |
584 } | 584 } |
585 } | 585 } |
586 }); | 586 }); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 Future<HttpClientResponse> future; | 887 Future<HttpClientResponse> future; |
888 if (followRedirects && response.isRedirect) { | 888 if (followRedirects && response.isRedirect) { |
889 if (response.redirects.length < maxRedirects) { | 889 if (response.redirects.length < maxRedirects) { |
890 // Redirect and drain response. | 890 // Redirect and drain response. |
891 future = response.drain() | 891 future = response.drain() |
892 .then((_) => response.redirect()); | 892 .then((_) => response.redirect()); |
893 } else { | 893 } else { |
894 // End with exception, too many redirects. | 894 // End with exception, too many redirects. |
895 future = response.drain() | 895 future = response.drain() |
896 .then((_) => new Future.error( | 896 .then((_) => new Future.error( |
897 new RedirectLimitExceededException(response.redirects))); | 897 new RedirectException("Redirect limit exceeded", |
| 898 response.redirects))); |
898 } | 899 } |
899 } else if (response._shouldAuthenticateProxy) { | 900 } else if (response._shouldAuthenticateProxy) { |
900 future = response._authenticate(true); | 901 future = response._authenticate(true); |
901 } else if (response._shouldAuthenticate) { | 902 } else if (response._shouldAuthenticate) { |
902 future = response._authenticate(false); | 903 future = response._authenticate(false); |
903 } else { | 904 } else { |
904 future = new Future<HttpClientResponse>.value(response); | 905 future = new Future<HttpClientResponse>.value(response); |
905 } | 906 } |
906 future.then( | 907 future.then( |
907 (v) => _responseCompleter.complete(v), | 908 (v) => _responseCompleter.complete(v), |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 _HeaderValue.parse( | 1221 _HeaderValue.parse( |
1221 authInfo[0], parameterSeparator: ','); | 1222 authInfo[0], parameterSeparator: ','); |
1222 var nextnonce = header.parameters["nextnonce"]; | 1223 var nextnonce = header.parameters["nextnonce"]; |
1223 if (nextnonce != null) creds.nonce = nextnonce; | 1224 if (nextnonce != null) creds.nonce = nextnonce; |
1224 } | 1225 } |
1225 } | 1226 } |
1226 request._onIncoming(incoming); | 1227 request._onIncoming(incoming); |
1227 }) | 1228 }) |
1228 // If we see a state error, we failed to get the 'first' | 1229 // If we see a state error, we failed to get the 'first' |
1229 // element. | 1230 // element. |
1230 // Transform the error to a HttpParserException, for | |
1231 // consistency. | |
1232 .catchError((error) { | 1231 .catchError((error) { |
1233 throw new HttpParserException( | 1232 throw new HttpException( |
1234 "Connection closed before data was received"); | 1233 "Connection closed before data was received"); |
1235 }, test: (error) => error is StateError) | 1234 }, test: (error) => error is StateError) |
1236 .catchError((error) { | 1235 .catchError((error) { |
1237 // We are done with the socket. | 1236 // We are done with the socket. |
1238 destroy(); | 1237 destroy(); |
1239 request._onError(error); | 1238 request._onError(error); |
1240 }); | 1239 }); |
1241 | 1240 |
1242 // Resume the parser now we have a handler. | 1241 // Resume the parser now we have a handler. |
1243 _subscription.resume(); | 1242 _subscription.resume(); |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2342 | 2341 |
2343 | 2342 |
2344 class _RedirectInfo implements RedirectInfo { | 2343 class _RedirectInfo implements RedirectInfo { |
2345 const _RedirectInfo(int this.statusCode, | 2344 const _RedirectInfo(int this.statusCode, |
2346 String this.method, | 2345 String this.method, |
2347 Uri this.location); | 2346 Uri this.location); |
2348 final int statusCode; | 2347 final int statusCode; |
2349 final String method; | 2348 final String method; |
2350 final Uri location; | 2349 final Uri location; |
2351 } | 2350 } |
OLD | NEW |