| 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 return statusCode == HttpStatus.UNAUTHORIZED && | 253 return statusCode == HttpStatus.UNAUTHORIZED && |
| 254 challenge != null && challenge.length == 1; | 254 challenge != null && challenge.length == 1; |
| 255 } | 255 } |
| 256 | 256 |
| 257 Future<HttpClientResponse> _authenticate() { | 257 Future<HttpClientResponse> _authenticate() { |
| 258 Future<HttpClientResponse> retryWithCredentials(_Credentials cr) { | 258 Future<HttpClientResponse> retryWithCredentials(_Credentials cr) { |
| 259 if (cr != null) { | 259 if (cr != null) { |
| 260 // TODO(sgjesse): Support digest. | 260 // TODO(sgjesse): Support digest. |
| 261 if (cr.scheme == _AuthenticationScheme.BASIC) { | 261 if (cr.scheme == _AuthenticationScheme.BASIC) { |
| 262 // Drain body and retry. | 262 // Drain body and retry. |
| 263 return reduce(null, (x, y) {}).then((_) { | 263 return fold(null, (x, y) {}).then((_) { |
| 264 return _httpClient._openUrlFromRequest(_httpRequest.method, | 264 return _httpClient._openUrlFromRequest(_httpRequest.method, |
| 265 _httpRequest.uri, | 265 _httpRequest.uri, |
| 266 _httpRequest) | 266 _httpRequest) |
| 267 .then((request) => request.close()); | 267 .then((request) => request.close()); |
| 268 }); | 268 }); |
| 269 } | 269 } |
| 270 } | 270 } |
| 271 | 271 |
| 272 // Fall through to here to perform normal response handling if | 272 // Fall through to here to perform normal response handling if |
| 273 // there is no sensible authorization handling. | 273 // there is no sensible authorization handling. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 445 } |
| 446 _writeHeader(); | 446 _writeHeader(); |
| 447 _ioSink = new IOSink(new _HttpOutboundConsumer(_ioSink, _consume, asGZip)); | 447 _ioSink = new IOSink(new _HttpOutboundConsumer(_ioSink, _consume, asGZip)); |
| 448 _ioSink.encoding = encoding; | 448 _ioSink.encoding = encoding; |
| 449 } | 449 } |
| 450 | 450 |
| 451 Future _consume(IOSink ioSink, Stream<List<int>> stream, bool asGZip) { | 451 Future _consume(IOSink ioSink, Stream<List<int>> stream, bool asGZip) { |
| 452 int contentLength = headers.contentLength; | 452 int contentLength = headers.contentLength; |
| 453 if (_ignoreBody) { | 453 if (_ignoreBody) { |
| 454 ioSink.close(); | 454 ioSink.close(); |
| 455 return stream.reduce(null, (x, y) {}).then((_) => this); | 455 return stream.fold(null, (x, y) {}).then((_) => this); |
| 456 } | 456 } |
| 457 stream = stream.transform(new _BufferTransformer()); | 457 stream = stream.transform(new _BufferTransformer()); |
| 458 if (headers.chunkedTransferEncoding) { | 458 if (headers.chunkedTransferEncoding) { |
| 459 if (asGZip) { | 459 if (asGZip) { |
| 460 stream = stream.transform(new ZLibDeflater(gzip: true, level: 6)); | 460 stream = stream.transform(new ZLibDeflater(gzip: true, level: 6)); |
| 461 } | 461 } |
| 462 stream = stream.transform(new _ChunkedTransformer()); | 462 stream = stream.transform(new _ChunkedTransformer()); |
| 463 } else if (contentLength >= 0) { | 463 } else if (contentLength >= 0) { |
| 464 stream = stream.transform(new _ContentLengthValidator(contentLength)); | 464 stream = stream.transform(new _ContentLengthValidator(contentLength)); |
| 465 } | 465 } |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 HttpConnectionInfo get connectionInfo => _httpClientConnection.connectionInfo; | 720 HttpConnectionInfo get connectionInfo => _httpClientConnection.connectionInfo; |
| 721 | 721 |
| 722 void _onIncoming(_HttpIncoming incoming) { | 722 void _onIncoming(_HttpIncoming incoming) { |
| 723 var response = new _HttpClientResponse(incoming, | 723 var response = new _HttpClientResponse(incoming, |
| 724 this, | 724 this, |
| 725 _httpClient); | 725 _httpClient); |
| 726 Future<HttpClientResponse> future; | 726 Future<HttpClientResponse> future; |
| 727 if (followRedirects && response.isRedirect) { | 727 if (followRedirects && response.isRedirect) { |
| 728 if (response.redirects.length < maxRedirects) { | 728 if (response.redirects.length < maxRedirects) { |
| 729 // Redirect and drain response. | 729 // Redirect and drain response. |
| 730 future = response.reduce(null, (x, y) {}) | 730 future = response.fold(null, (x, y) {}) |
| 731 .then((_) => response.redirect()); | 731 .then((_) => response.redirect()); |
| 732 } else { | 732 } else { |
| 733 // End with exception, too many redirects. | 733 // End with exception, too many redirects. |
| 734 future = response.reduce(null, (x, y) {}) | 734 future = response.fold(null, (x, y) {}) |
| 735 .then((_) => new Future.immediateError( | 735 .then((_) => new Future.immediateError( |
| 736 new RedirectLimitExceededException(response.redirects))); | 736 new RedirectLimitExceededException(response.redirects))); |
| 737 } | 737 } |
| 738 } else if (response._shouldAuthenticate) { | 738 } else if (response._shouldAuthenticate) { |
| 739 future = response._authenticate(); | 739 future = response._authenticate(); |
| 740 } else { | 740 } else { |
| 741 future = new Future<HttpClientResponse>.immediate(response); | 741 future = new Future<HttpClientResponse>.immediate(response); |
| 742 } | 742 } |
| 743 future.then( | 743 future.then( |
| 744 (v) => _responseCompleter.complete(v), | 744 (v) => _responseCompleter.complete(v), |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 } | 1082 } |
| 1083 | 1083 |
| 1084 Future<HttpClientRequest> postUrl(Uri url) { | 1084 Future<HttpClientRequest> postUrl(Uri url) { |
| 1085 return _openUrl("post", url); | 1085 return _openUrl("post", url); |
| 1086 } | 1086 } |
| 1087 | 1087 |
| 1088 void close({bool force: false}) { | 1088 void close({bool force: false}) { |
| 1089 _closing = true; | 1089 _closing = true; |
| 1090 // Create flattened copy of _idleConnections, as 'destory' will manipulate | 1090 // Create flattened copy of _idleConnections, as 'destory' will manipulate |
| 1091 // it. | 1091 // it. |
| 1092 var idle = _idleConnections.values.reduce( | 1092 var idle = _idleConnections.values.fold( |
| 1093 [], | 1093 [], |
| 1094 (l, e) { | 1094 (l, e) { |
| 1095 l.addAll(e); | 1095 l.addAll(e); |
| 1096 return l; | 1096 return l; |
| 1097 }); | 1097 }); |
| 1098 idle.forEach((e) { | 1098 idle.forEach((e) { |
| 1099 e.close(); | 1099 e.close(); |
| 1100 }); | 1100 }); |
| 1101 assert(_idleConnections.isEmpty); | 1101 assert(_idleConnections.isEmpty); |
| 1102 if (force) { | 1102 if (force) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1234 // Continue with next proxy. | 1234 // Continue with next proxy. |
| 1235 return connect(error.error); | 1235 return connect(error.error); |
| 1236 }); | 1236 }); |
| 1237 } | 1237 } |
| 1238 return connect(new HttpException("No proxies given")); | 1238 return connect(new HttpException("No proxies given")); |
| 1239 } | 1239 } |
| 1240 | 1240 |
| 1241 _Credentials _findCredentials(Uri url, [_AuthenticationScheme scheme]) { | 1241 _Credentials _findCredentials(Uri url, [_AuthenticationScheme scheme]) { |
| 1242 // Look for credentials. | 1242 // Look for credentials. |
| 1243 _Credentials cr = | 1243 _Credentials cr = |
| 1244 _credentials.reduce(null, (_Credentials prev, _Credentials value) { | 1244 _credentials.fold(null, (_Credentials prev, _Credentials value) { |
| 1245 if (value.applies(url, scheme)) { | 1245 if (value.applies(url, scheme)) { |
| 1246 if (prev == null) return value; | 1246 if (prev == null) return value; |
| 1247 return value.uri.path.length > prev.uri.path.length ? value : prev; | 1247 return value.uri.path.length > prev.uri.path.length ? value : prev; |
| 1248 } else { | 1248 } else { |
| 1249 return prev; | 1249 return prev; |
| 1250 } | 1250 } |
| 1251 }); | 1251 }); |
| 1252 return cr; | 1252 return cr; |
| 1253 } | 1253 } |
| 1254 | 1254 |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 | 1770 |
| 1771 | 1771 |
| 1772 class _RedirectInfo implements RedirectInfo { | 1772 class _RedirectInfo implements RedirectInfo { |
| 1773 const _RedirectInfo(int this.statusCode, | 1773 const _RedirectInfo(int this.statusCode, |
| 1774 String this.method, | 1774 String this.method, |
| 1775 Uri this.location); | 1775 Uri this.location); |
| 1776 final int statusCode; | 1776 final int statusCode; |
| 1777 final String method; | 1777 final String method; |
| 1778 final Uri location; | 1778 final Uri location; |
| 1779 } | 1779 } |
| OLD | NEW |