Chromium Code Reviews| Index: sdk/lib/io/http_impl.dart |
| diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart |
| index 846b724f389b87e0ec7dc6cd62868a959f0c78a7..02f24eaca083b70f586029883c4412e8e79d7749 100644 |
| --- a/sdk/lib/io/http_impl.dart |
| +++ b/sdk/lib/io/http_impl.dart |
| @@ -129,13 +129,14 @@ class _HttpRequest extends _HttpInboundMessage implements HttpRequest { |
| var proto = headers['x-forwarded-proto']; |
| var scheme = proto != null ? proto.first : |
| _httpConnection._socket is SecureSocket ? "https" : "http"; |
| - var host = headers['x-forwarded-host']; |
| - if (host != null) { |
| - host = host.first; |
| + var hostList = headers['x-forwarded-host']; |
| + String host; |
| + if (hostList != null) { |
| + host = hostList.first; |
| } else { |
| - host = headers['host']; |
| - if (host != null) { |
| - host = host.first; |
| + hostList = headers['host']; |
| + if (hostList != null) { |
| + host = hostList.first; |
| } else { |
| host = "${_httpServer.address.host}:${_httpServer.port}"; |
| } |
| @@ -182,8 +183,6 @@ class _HttpClientResponse |
| // The HttpClientRequest of this response. |
| final _HttpClientRequest _httpRequest; |
| - List<Cookie> _cookies; |
| - |
| _HttpClientResponse(_HttpIncoming _incoming, this._httpRequest, |
| this._httpClient) : super(_incoming) { |
| // Set uri for potential exceptions. |
| @@ -194,9 +193,8 @@ class _HttpClientResponse |
| String get reasonPhrase => _incoming.reasonPhrase; |
| X509Certificate get certificate { |
|
Søren Gjesse
2016/05/04 16:14:09
Maybe add an is-check to throw a better exception?
floitsch
2016/05/04 18:28:41
Done.
|
| - // The peerCertificate isn't on a plain socket, so cast to dynamic. |
| - var socket = _httpRequest._httpClientConnection._socket; |
| - return socket.peerCertificate; |
| + return (_httpRequest._httpClientConnection._socket as SecureSocket) |
| + .peerCertificate; |
| } |
| List<Cookie> get cookies { |
| @@ -869,8 +867,12 @@ class _HttpGZipSink extends ByteConversionSink { |
| _consume(chunk); |
| } |
| - void addSlice(Uint8List chunk, int start, int end, bool isLast) { |
| - _consume(new Uint8List.view(chunk.buffer, start, end - start)); |
| + void addSlice(List<int> chunk, int start, int end, bool isLast) { |
| + if (chunk is Uint8List) { |
| + _consume(new Uint8List.view(chunk.buffer, start, end - start)); |
| + } else { |
| + _consume(chunk.sublist(start, end - start)); |
| + } |
| } |
| void close() {} |
| @@ -936,14 +938,16 @@ class _HttpOutgoing implements StreamConsumer<List<int>> { |
| "Headers size exceeded the of '$_OUTGOING_BUFFER_SIZE'" |
| " bytes")); |
| } |
| + return null; |
| } |
| + |
| if (headersWritten) return null; |
| headersWritten = true; |
| Future drainFuture; |
| - bool isServerSide = outbound is _HttpResponse; |
| bool gzip = false; |
| - if (isServerSide) { |
| - var response = outbound; |
| + if (outbound is _HttpResponse) { |
| + // Server side. |
| + _HttpResponse response = outbound; |
| if (response._httpRequest._httpServer.autoCompress && |
| outbound.bufferOutput && |
| outbound.headers.chunkedTransferEncoding) { |
| @@ -1495,7 +1499,8 @@ class _HttpClientConnection { |
| throw "Proxy failed to establish tunnel " |
| "(${response.statusCode} ${response.reasonPhrase})"; |
| } |
| - var socket = response._httpRequest._httpClientConnection._socket; |
| + var socket = (response as _HttpClientResponse)._httpRequest |
| + ._httpClientConnection._socket; |
| return SecureSocket.secure( |
| socket, |
| host: host, |
| @@ -1629,9 +1634,12 @@ class _ConnectionTarget { |
| return completer.future; |
| } |
| var currentBadCertificateCallback = client._badCertificateCallback; |
| - callback(X509Certificate certificate) => |
| - currentBadCertificateCallback == null ? false : |
| - currentBadCertificateCallback(certificate, uriHost, uriPort); |
| + |
| + bool callback(X509Certificate certificate) { |
| + if (currentBadCertificateCallback == null) return false; |
| + return currentBadCertificateCallback(certificate, uriHost, uriPort); |
| + } |
| + |
| Future socketFuture = (isSecure && proxy.isDirect |
| ? SecureSocket.connect(host, |
| port, |
| @@ -1664,6 +1672,7 @@ class _ConnectionTarget { |
| } |
| } |
| +typedef bool BadCertificateCallback(X509Certificate cr, String host, int port); |
| class _HttpClient implements HttpClient { |
| bool _closing = false; |
| @@ -1677,7 +1686,7 @@ class _HttpClient implements HttpClient { |
| Function _authenticateProxy; |
| Function _findProxy = HttpClient.findProxyFromEnvironment; |
| Duration _idleTimeout = const Duration(seconds: 15); |
| - Function _badCertificateCallback; |
| + BadCertificateCallback _badCertificateCallback; |
| Duration get idleTimeout => _idleTimeout; |
| @@ -1734,9 +1743,8 @@ class _HttpClient implements HttpClient { |
| return _openUrl(method, uri); |
| } |
| - Future<HttpClientRequest> openUrl(String method, Uri url) { |
| - return _openUrl(method, url); |
| - } |
| + Future<HttpClientRequest> openUrl(String method, Uri url) |
| + => _openUrl(method, url); |
| Future<HttpClientRequest> get(String host, int port, String path) |
| => open("get", host, port, path); |
| @@ -1799,7 +1807,7 @@ class _HttpClient implements HttpClient { |
| set findProxy(String f(Uri uri)) => _findProxy = f; |
| - Future<HttpClientRequest> _openUrl(String method, Uri uri) { |
| + Future<_HttpClientRequest> _openUrl(String method, Uri uri) { |
| // Ignore any fragments on the request URI. |
| uri = uri.removeFragment(); |
| @@ -1834,13 +1842,15 @@ class _HttpClient implements HttpClient { |
| } |
| } |
| return _getConnection(uri.host, port, proxyConf, isSecure) |
| - .then((info) { |
| - send(info) { |
| + .then((_ConnectionInfo info) { |
| + |
| + _HttpClientRequest send(_ConnectionInfo info) { |
| return info.connection.send(uri, |
| port, |
| method.toUpperCase(), |
| info.proxy); |
| } |
| + |
| // If the connection was closed before the request was sent, create |
| // and use another connection. |
| if (info.connection.closed) { |
| @@ -1851,13 +1861,13 @@ class _HttpClient implements HttpClient { |
| }); |
| } |
| - Future<HttpClientRequest> _openUrlFromRequest(String method, |
| + Future<_HttpClientRequest> _openUrlFromRequest(String method, |
| Uri uri, |
| _HttpClientRequest previous) { |
| // If the new URI is relative (to either '/' or some sub-path), |
| // construct a full URI from the previous one. |
| Uri resolved = previous.uri.resolveUri(uri); |
| - return openUrl(method, resolved).then((_HttpClientRequest request) { |
| + return _openUrl(method, resolved).then((_HttpClientRequest request) { |
| request |
| // Only follow redirects if initial request did. |
| @@ -1941,10 +1951,13 @@ class _HttpClient implements HttpClient { |
| _SiteCredentials _findCredentials(Uri url, [_AuthenticationScheme scheme]) { |
| // Look for credentials. |
| _SiteCredentials cr = |
| - _credentials.fold(null, (prev, value) { |
| - if (value.applies(url, scheme)) { |
| + _credentials.fold(null, (_SiteCredentials prev, value) { |
| + var siteCredentials = value as _SiteCredentials; |
| + if (siteCredentials.applies(url, scheme)) { |
| if (prev == null) return value; |
| - return value.uri.path.length > prev.uri.path.length ? value : prev; |
| + return siteCredentials.uri.path.length > prev.uri.path.length |
| + ? siteCredentials |
| + : prev; |
| } else { |
| return prev; |
| } |
| @@ -1961,6 +1974,7 @@ class _HttpClient implements HttpClient { |
| return it.current; |
| } |
| } |
| + return null; |
| } |
| void _removeCredentials(_Credentials cr) { |
| @@ -2166,7 +2180,7 @@ class _HttpConnection |
| Map _toJSON(bool ref) { |
| var name = "${_socket.address.host}:${_socket.port} <-> " |
| "${_socket.remoteAddress.host}:${_socket.remotePort}"; |
| - var r = { |
| + var r = <String, dynamic>{ |
| 'id': _servicePath, |
| 'type': _serviceType(ref), |
| 'name': name, |
| @@ -2412,8 +2426,8 @@ class _HttpServer |
| String get _serviceTypePath => 'io/http/servers'; |
| String get _serviceTypeName => 'HttpServer'; |
| - Map _toJSON(bool ref) { |
| - var r = { |
| + Map<String, dynamic> _toJSON(bool ref) { |
| + var r = <String, dynamic>{ |
| 'id': _servicePath, |
| 'type': _serviceType(ref), |
| 'name': '${address.host}:$port', |