| 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 class _HttpHeaders implements HttpHeaders { | 5 class _HttpHeaders implements HttpHeaders { |
| 6 _HttpHeaders() : _headers = new Map<String, List<String>>(); | 6 _HttpHeaders() : _headers = new Map<String, List<String>>(); |
| 7 | 7 |
| 8 List<String> operator[](String name) { | 8 List<String> operator[](String name) { |
| 9 name = name.toLowerCase(); | 9 name = name.toLowerCase(); |
| 10 return _headers[name]; | 10 return _headers[name]; |
| (...skipping 2311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2322 } | 2322 } |
| 2323 | 2323 |
| 2324 HttpClientConnection _prepareHttpClientConnection( | 2324 HttpClientConnection _prepareHttpClientConnection( |
| 2325 String method, | 2325 String method, |
| 2326 Uri url, | 2326 Uri url, |
| 2327 [_HttpClientConnection connection]) { | 2327 [_HttpClientConnection connection]) { |
| 2328 | 2328 |
| 2329 void _establishConnection(String host, | 2329 void _establishConnection(String host, |
| 2330 int port, | 2330 int port, |
| 2331 _ProxyConfiguration proxyConfiguration, | 2331 _ProxyConfiguration proxyConfiguration, |
| 2332 int proxyIndex) { | 2332 int proxyIndex, |
| 2333 bool reusedConnection) { |
| 2333 | 2334 |
| 2334 void _connectionOpened(_SocketConnection socketConn, | 2335 void _connectionOpened(_SocketConnection socketConn, |
| 2335 _HttpClientConnection connection, | 2336 _HttpClientConnection connection, |
| 2336 bool usingProxy) { | 2337 bool usingProxy) { |
| 2337 connection._usingProxy = usingProxy; | 2338 connection._usingProxy = usingProxy; |
| 2338 connection._connectionEstablished(socketConn); | 2339 connection._connectionEstablished(socketConn); |
| 2339 HttpClientRequest request = connection.open(method, url); | 2340 HttpClientRequest request = connection.open(method, url); |
| 2340 request.headers.host = host; | 2341 request.headers.host = host; |
| 2341 request.headers.port = port; | 2342 request.headers.port = port; |
| 2342 if (url.userInfo != null && !url.userInfo.isEmpty) { | 2343 if (url.userInfo != null && !url.userInfo.isEmpty) { |
| 2343 // If the URL contains user information use that for basic | 2344 // If the URL contains user information use that for basic |
| 2344 // authorization | 2345 // authorization |
| 2345 _UTF8Encoder encoder = new _UTF8Encoder(); | 2346 _UTF8Encoder encoder = new _UTF8Encoder(); |
| 2346 String auth = | 2347 String auth = |
| 2347 CryptoUtils.bytesToBase64(encoder.encodeString(url.userInfo)); | 2348 CryptoUtils.bytesToBase64(encoder.encodeString(url.userInfo)); |
| 2348 request.headers.set(HttpHeaders.AUTHORIZATION, "Basic $auth"); | 2349 request.headers.set(HttpHeaders.AUTHORIZATION, "Basic $auth"); |
| 2349 } else { | 2350 } else { |
| 2350 // Look for credentials. | 2351 // Look for credentials. |
| 2351 _Credentials cr = _findCredentials(url); | 2352 _Credentials cr = _findCredentials(url); |
| 2352 if (cr != null) { | 2353 if (cr != null) { |
| 2353 cr.authorize(request); | 2354 cr.authorize(request); |
| 2354 } | 2355 } |
| 2355 } | 2356 } |
| 2356 if (connection._onRequest != null) { | 2357 // A reused connection is indicating either redirect or retry |
| 2358 // where the onRequest callback should not be issued again. |
| 2359 if (connection._onRequest != null && !reusedConnection) { |
| 2357 connection._onRequest(request); | 2360 connection._onRequest(request); |
| 2358 } else { | 2361 } else { |
| 2359 request.outputStream.close(); | 2362 request.outputStream.close(); |
| 2360 } | 2363 } |
| 2361 } | 2364 } |
| 2362 | 2365 |
| 2363 assert(proxyIndex < proxyConfiguration.proxies.length); | 2366 assert(proxyIndex < proxyConfiguration.proxies.length); |
| 2364 | 2367 |
| 2365 // Determine the actual host to connect to. | 2368 // Determine the actual host to connect to. |
| 2366 String connectHost; | 2369 String connectHost; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2415 if (socketConnections.isEmpty) _openSockets.remove(key); | 2418 if (socketConnections.isEmpty) _openSockets.remove(key); |
| 2416 if (_openSockets.isEmpty) _cancelEvictionTimer(); | 2419 if (_openSockets.isEmpty) _cancelEvictionTimer(); |
| 2417 } | 2420 } |
| 2418 } | 2421 } |
| 2419 | 2422 |
| 2420 // Find the TCP host and port. | 2423 // Find the TCP host and port. |
| 2421 String host = url.domain; | 2424 String host = url.domain; |
| 2422 int port = url.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : url.port; | 2425 int port = url.port == 0 ? HttpClient.DEFAULT_HTTP_PORT : url.port; |
| 2423 | 2426 |
| 2424 // Create a new connection object if we are not re-using an existing one. | 2427 // Create a new connection object if we are not re-using an existing one. |
| 2428 var reusedConnection = false; |
| 2425 if (connection == null) { | 2429 if (connection == null) { |
| 2426 connection = new _HttpClientConnection(this); | 2430 connection = new _HttpClientConnection(this); |
| 2431 } else { |
| 2432 reusedConnection = true; |
| 2427 } | 2433 } |
| 2428 connection.onDetach = () => _activeSockets.remove(connection._socketConn); | 2434 connection.onDetach = () => _activeSockets.remove(connection._socketConn); |
| 2429 | 2435 |
| 2430 // Check to see if a proxy server should be used for this connection. | 2436 // Check to see if a proxy server should be used for this connection. |
| 2431 _ProxyConfiguration proxyConfiguration = const _ProxyConfiguration.direct(); | 2437 _ProxyConfiguration proxyConfiguration = const _ProxyConfiguration.direct(); |
| 2432 if (_findProxy != null) { | 2438 if (_findProxy != null) { |
| 2433 // TODO(sgjesse): Keep a map of these as normally only a few | 2439 // TODO(sgjesse): Keep a map of these as normally only a few |
| 2434 // configuration strings will be used. | 2440 // configuration strings will be used. |
| 2435 proxyConfiguration = new _ProxyConfiguration(_findProxy(url)); | 2441 proxyConfiguration = new _ProxyConfiguration(_findProxy(url)); |
| 2436 } | 2442 } |
| 2437 | 2443 |
| 2438 // Establish the connection starting with the first proxy configured. | 2444 // Establish the connection starting with the first proxy configured. |
| 2439 _establishConnection(host, port, proxyConfiguration, 0); | 2445 _establishConnection(host, port, proxyConfiguration, 0, reusedConnection); |
| 2440 | 2446 |
| 2441 return connection; | 2447 return connection; |
| 2442 } | 2448 } |
| 2443 | 2449 |
| 2444 void _returnSocketConnection(_SocketConnection socketConn) { | 2450 void _returnSocketConnection(_SocketConnection socketConn) { |
| 2445 // Mark socket as returned to unregister from the old connection. | 2451 // Mark socket as returned to unregister from the old connection. |
| 2446 socketConn._markReturned(); | 2452 socketConn._markReturned(); |
| 2447 | 2453 |
| 2448 // If the HTTP client is beeing shutdown don't return the connection. | 2454 // If the HTTP client is beeing shutdown don't return the connection. |
| 2449 if (_shutdown) { | 2455 if (_shutdown) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2648 | 2654 |
| 2649 | 2655 |
| 2650 class _RedirectInfo implements RedirectInfo { | 2656 class _RedirectInfo implements RedirectInfo { |
| 2651 const _RedirectInfo(int this.statusCode, | 2657 const _RedirectInfo(int this.statusCode, |
| 2652 String this.method, | 2658 String this.method, |
| 2653 Uri this.location); | 2659 Uri this.location); |
| 2654 final int statusCode; | 2660 final int statusCode; |
| 2655 final String method; | 2661 final String method; |
| 2656 final Uri location; | 2662 final Uri location; |
| 2657 } | 2663 } |
| OLD | NEW |