| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 if (url == null) { | 208 if (url == null) { |
| 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.immediateError( | 218 return new Future.error( |
| 219 new RedirectLoopException(redirects)); | 219 new RedirectLoopException(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)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 return _httpClient._openUrlFromRequest(_httpRequest.method, | 268 return _httpClient._openUrlFromRequest(_httpRequest.method, |
| 269 _httpRequest.uri, | 269 _httpRequest.uri, |
| 270 _httpRequest) | 270 _httpRequest) |
| 271 .then((request) => request.close()); | 271 .then((request) => request.close()); |
| 272 }); | 272 }); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 // Fall through to here to perform normal response handling if | 276 // Fall through to here to perform normal response handling if |
| 277 // there is no sensible authorization handling. | 277 // there is no sensible authorization handling. |
| 278 return new Future.immediate(this); | 278 return new Future.value(this); |
| 279 } | 279 } |
| 280 | 280 |
| 281 List<String> challenge = headers[HttpHeaders.WWW_AUTHENTICATE]; | 281 List<String> challenge = headers[HttpHeaders.WWW_AUTHENTICATE]; |
| 282 assert(challenge != null || challenge.length == 1); | 282 assert(challenge != null || challenge.length == 1); |
| 283 _HeaderValue header = | 283 _HeaderValue header = |
| 284 new _HeaderValue.fromString(challenge[0], parameterSeparator: ","); | 284 new _HeaderValue.fromString(challenge[0], parameterSeparator: ","); |
| 285 _AuthenticationScheme scheme = | 285 _AuthenticationScheme scheme = |
| 286 new _AuthenticationScheme.fromString(header.value); | 286 new _AuthenticationScheme.fromString(header.value); |
| 287 String realm = header.parameters["realm"]; | 287 String realm = header.parameters["realm"]; |
| 288 | 288 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 309 if (credsAvailable) { | 309 if (credsAvailable) { |
| 310 cr = _httpClient._findCredentials(_httpRequest.uri, scheme); | 310 cr = _httpClient._findCredentials(_httpRequest.uri, scheme); |
| 311 return retryWithCredentials(cr); | 311 return retryWithCredentials(cr); |
| 312 } else { | 312 } else { |
| 313 // No credentials available, complete with original response. | 313 // No credentials available, complete with original response. |
| 314 return this; | 314 return this; |
| 315 } | 315 } |
| 316 }); | 316 }); |
| 317 } | 317 } |
| 318 // No credentials were found and the callback was not set. | 318 // No credentials were found and the callback was not set. |
| 319 return new Future.immediate(this); | 319 return new Future.value(this); |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 | 322 |
| 323 | 323 |
| 324 abstract class _HttpOutboundMessage<T> implements IOSink { | 324 abstract class _HttpOutboundMessage<T> implements IOSink { |
| 325 // Used to mark when the body should be written. This is used for HEAD | 325 // Used to mark when the body should be written. This is used for HEAD |
| 326 // requests and in error handling. | 326 // requests and in error handling. |
| 327 bool _ignoreBody = false; | 327 bool _ignoreBody = false; |
| 328 bool _headersWritten = false; | 328 bool _headersWritten = false; |
| 329 | 329 |
| (...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 _httpClient); | 767 _httpClient); |
| 768 Future<HttpClientResponse> future; | 768 Future<HttpClientResponse> future; |
| 769 if (followRedirects && response.isRedirect) { | 769 if (followRedirects && response.isRedirect) { |
| 770 if (response.redirects.length < maxRedirects) { | 770 if (response.redirects.length < maxRedirects) { |
| 771 // Redirect and drain response. | 771 // Redirect and drain response. |
| 772 future = response.fold(null, (x, y) {}) | 772 future = response.fold(null, (x, y) {}) |
| 773 .then((_) => response.redirect()); | 773 .then((_) => response.redirect()); |
| 774 } else { | 774 } else { |
| 775 // End with exception, too many redirects. | 775 // End with exception, too many redirects. |
| 776 future = response.fold(null, (x, y) {}) | 776 future = response.fold(null, (x, y) {}) |
| 777 .then((_) => new Future.immediateError( | 777 .then((_) => new Future.error( |
| 778 new RedirectLimitExceededException(response.redirects))); | 778 new RedirectLimitExceededException(response.redirects))); |
| 779 } | 779 } |
| 780 } else if (response._shouldAuthenticate) { | 780 } else if (response._shouldAuthenticate) { |
| 781 future = response._authenticate(); | 781 future = response._authenticate(); |
| 782 } else { | 782 } else { |
| 783 future = new Future<HttpClientResponse>.immediate(response); | 783 future = new Future<HttpClientResponse>.value(response); |
| 784 } | 784 } |
| 785 future.then( | 785 future.then( |
| 786 (v) => _responseCompleter.complete(v), | 786 (v) => _responseCompleter.complete(v), |
| 787 onError: (e) { | 787 onError: (e) { |
| 788 _responseCompleter.completeError(e); | 788 _responseCompleter.completeError(e); |
| 789 }); | 789 }); |
| 790 } | 790 } |
| 791 | 791 |
| 792 void _onError(AsyncError error) { | 792 void _onError(AsyncError error) { |
| 793 _responseCompleter.completeError(error); | 793 _responseCompleter.completeError(error); |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 HttpClient.DEFAULT_HTTP_PORT; | 1181 HttpClient.DEFAULT_HTTP_PORT; |
| 1182 } | 1182 } |
| 1183 // Check to see if a proxy server should be used for this connection. | 1183 // Check to see if a proxy server should be used for this connection. |
| 1184 var proxyConf = const _ProxyConfiguration.direct(); | 1184 var proxyConf = const _ProxyConfiguration.direct(); |
| 1185 if (_findProxy != null) { | 1185 if (_findProxy != null) { |
| 1186 // TODO(sgjesse): Keep a map of these as normally only a few | 1186 // TODO(sgjesse): Keep a map of these as normally only a few |
| 1187 // configuration strings will be used. | 1187 // configuration strings will be used. |
| 1188 try { | 1188 try { |
| 1189 proxyConf = new _ProxyConfiguration(_findProxy(uri)); | 1189 proxyConf = new _ProxyConfiguration(_findProxy(uri)); |
| 1190 } catch (error, stackTrace) { | 1190 } catch (error, stackTrace) { |
| 1191 return new Future.immediateError(error, stackTrace); | 1191 return new Future.error(error, stackTrace); |
| 1192 } | 1192 } |
| 1193 } | 1193 } |
| 1194 return _getConnection(uri.domain, port, proxyConf, isSecure) | 1194 return _getConnection(uri.domain, port, proxyConf, isSecure) |
| 1195 .then((info) { | 1195 .then((info) { |
| 1196 return info.connection.send(uri, | 1196 return info.connection.send(uri, |
| 1197 port, | 1197 port, |
| 1198 method.toUpperCase(), | 1198 method.toUpperCase(), |
| 1199 info.proxy.isDirect); | 1199 info.proxy.isDirect); |
| 1200 }); | 1200 }); |
| 1201 } | 1201 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1247 | 1247 |
| 1248 // Get a new _HttpClientConnection, either from the idle pool or created from | 1248 // Get a new _HttpClientConnection, either from the idle pool or created from |
| 1249 // a new Socket. | 1249 // a new Socket. |
| 1250 Future<_ConnnectionInfo> _getConnection(String uriHost, | 1250 Future<_ConnnectionInfo> _getConnection(String uriHost, |
| 1251 int uriPort, | 1251 int uriPort, |
| 1252 _ProxyConfiguration proxyConf, | 1252 _ProxyConfiguration proxyConf, |
| 1253 bool isSecure) { | 1253 bool isSecure) { |
| 1254 Iterator<_Proxy> proxies = proxyConf.proxies.iterator; | 1254 Iterator<_Proxy> proxies = proxyConf.proxies.iterator; |
| 1255 | 1255 |
| 1256 Future<_ConnnectionInfo> connect(error) { | 1256 Future<_ConnnectionInfo> connect(error) { |
| 1257 if (!proxies.moveNext()) return new Future.immediateError(error); | 1257 if (!proxies.moveNext()) return new Future.error(error); |
| 1258 _Proxy proxy = proxies.current; | 1258 _Proxy proxy = proxies.current; |
| 1259 String host = proxy.isDirect ? uriHost: proxy.host; | 1259 String host = proxy.isDirect ? uriHost: proxy.host; |
| 1260 int port = proxy.isDirect ? uriPort: proxy.port; | 1260 int port = proxy.isDirect ? uriPort: proxy.port; |
| 1261 String key = isSecure ? "ssh:$host:$port" : "$host:$port"; | 1261 String key = isSecure ? "ssh:$host:$port" : "$host:$port"; |
| 1262 if (_idleConnections.containsKey(key)) { | 1262 if (_idleConnections.containsKey(key)) { |
| 1263 var connection = _idleConnections[key].first; | 1263 var connection = _idleConnections[key].first; |
| 1264 _idleConnections[key].remove(connection); | 1264 _idleConnections[key].remove(connection); |
| 1265 if (_idleConnections[key].isEmpty) { | 1265 if (_idleConnections[key].isEmpty) { |
| 1266 _idleConnections.remove(key); | 1266 _idleConnections.remove(key); |
| 1267 } | 1267 } |
| 1268 _activeConnections.add(connection); | 1268 _activeConnections.add(connection); |
| 1269 return new Future.immediate(new _ConnnectionInfo(connection, proxy)); | 1269 return new Future.value(new _ConnnectionInfo(connection, proxy)); |
| 1270 } | 1270 } |
| 1271 return (isSecure && proxy.isDirect | 1271 return (isSecure && proxy.isDirect |
| 1272 ? SecureSocket.connect(host, | 1272 ? SecureSocket.connect(host, |
| 1273 port, | 1273 port, |
| 1274 sendClientCertificate: true) | 1274 sendClientCertificate: true) |
| 1275 : Socket.connect(host, port)) | 1275 : Socket.connect(host, port)) |
| 1276 .then((socket) { | 1276 .then((socket) { |
| 1277 socket.setOption(SocketOption.TCP_NODELAY, true); | 1277 socket.setOption(SocketOption.TCP_NODELAY, true); |
| 1278 var connection = new _HttpClientConnection(key, socket, this); | 1278 var connection = new _HttpClientConnection(key, socket, this); |
| 1279 _activeConnections.add(connection); | 1279 _activeConnections.add(connection); |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1826 | 1826 |
| 1827 | 1827 |
| 1828 class _RedirectInfo implements RedirectInfo { | 1828 class _RedirectInfo implements RedirectInfo { |
| 1829 const _RedirectInfo(int this.statusCode, | 1829 const _RedirectInfo(int this.statusCode, |
| 1830 String this.method, | 1830 String this.method, |
| 1831 Uri this.location); | 1831 Uri this.location); |
| 1832 final int statusCode; | 1832 final int statusCode; |
| 1833 final String method; | 1833 final String method; |
| 1834 final Uri location; | 1834 final Uri location; |
| 1835 } | 1835 } |
| OLD | NEW |