| 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 403 |
| 404 final _HttpOutgoing _outgoing; | 404 final _HttpOutgoing _outgoing; |
| 405 final Uri _uri; | 405 final Uri _uri; |
| 406 | 406 |
| 407 final _HttpHeaders headers; | 407 final _HttpHeaders headers; |
| 408 | 408 |
| 409 _HttpOutboundMessage(Uri this._uri, | 409 _HttpOutboundMessage(Uri this._uri, |
| 410 String protocolVersion, | 410 String protocolVersion, |
| 411 _HttpOutgoing outgoing) | 411 _HttpOutgoing outgoing) |
| 412 : _outgoing = outgoing, | 412 : _outgoing = outgoing, |
| 413 _headersSink = new IOSink(outgoing, encoding: Encoding.ASCII), | 413 _headersSink = new IOSink(outgoing, encoding: ASCII), |
| 414 headers = new _HttpHeaders(protocolVersion) { | 414 headers = new _HttpHeaders(protocolVersion) { |
| 415 _dataSink = new IOSink(new _HttpOutboundConsumer(this)); | 415 _dataSink = new IOSink(new _HttpOutboundConsumer(this)); |
| 416 } | 416 } |
| 417 | 417 |
| 418 int get contentLength => headers.contentLength; | 418 int get contentLength => headers.contentLength; |
| 419 void set contentLength(int contentLength) { | 419 void set contentLength(int contentLength) { |
| 420 headers.contentLength = contentLength; | 420 headers.contentLength = contentLength; |
| 421 } | 421 } |
| 422 | 422 |
| 423 bool get persistentConnection => headers.persistentConnection; | 423 bool get persistentConnection => headers.persistentConnection; |
| 424 void set persistentConnection(bool p) { | 424 void set persistentConnection(bool p) { |
| 425 headers.persistentConnection = p; | 425 headers.persistentConnection = p; |
| 426 } | 426 } |
| 427 | 427 |
| 428 Encoding get encoding { | 428 Encoding get encoding { |
| 429 var charset; | 429 var charset; |
| 430 if (headers.contentType != null && headers.contentType.charset != null) { | 430 if (headers.contentType != null && headers.contentType.charset != null) { |
| 431 charset = headers.contentType.charset; | 431 charset = headers.contentType.charset; |
| 432 } else { | 432 } else { |
| 433 charset = "iso-8859-1"; | 433 charset = "iso-8859-1"; |
| 434 } | 434 } |
| 435 return Encoding.fromName(charset); | 435 return Encoding.getByName(charset); |
| 436 } | 436 } |
| 437 | 437 |
| 438 void set encoding(Encoding value) { | 438 void set encoding(Encoding value) { |
| 439 throw new StateError("IOSink encoding is not mutable"); | 439 throw new StateError("IOSink encoding is not mutable"); |
| 440 } | 440 } |
| 441 | 441 |
| 442 void write(Object obj) { | 442 void write(Object obj) { |
| 443 _dataSink.write(obj); | 443 _dataSink.write(obj); |
| 444 } | 444 } |
| 445 | 445 |
| (...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 request.headers.host = uri.host; | 1215 request.headers.host = uri.host; |
| 1216 request.headers.port = port; | 1216 request.headers.port = port; |
| 1217 request.headers.set(HttpHeaders.ACCEPT_ENCODING, "gzip"); | 1217 request.headers.set(HttpHeaders.ACCEPT_ENCODING, "gzip"); |
| 1218 if (_httpClient.userAgent != null) { | 1218 if (_httpClient.userAgent != null) { |
| 1219 request.headers.set('User-Agent', _httpClient.userAgent); | 1219 request.headers.set('User-Agent', _httpClient.userAgent); |
| 1220 } | 1220 } |
| 1221 if (proxy.isAuthenticated) { | 1221 if (proxy.isAuthenticated) { |
| 1222 // If the proxy configuration contains user information use that | 1222 // If the proxy configuration contains user information use that |
| 1223 // for proxy basic authorization. | 1223 // for proxy basic authorization. |
| 1224 String auth = _CryptoUtils.bytesToBase64( | 1224 String auth = _CryptoUtils.bytesToBase64( |
| 1225 _encodeString("${proxy.username}:${proxy.password}")); | 1225 UTF8.encode("${proxy.username}:${proxy.password}")); |
| 1226 request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, "Basic $auth"); | 1226 request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, "Basic $auth"); |
| 1227 } else if (!proxy.isDirect && _httpClient._proxyCredentials.length > 0) { | 1227 } else if (!proxy.isDirect && _httpClient._proxyCredentials.length > 0) { |
| 1228 proxyCreds = _httpClient._findProxyCredentials(proxy); | 1228 proxyCreds = _httpClient._findProxyCredentials(proxy); |
| 1229 if (proxyCreds != null) { | 1229 if (proxyCreds != null) { |
| 1230 proxyCreds.authorize(request); | 1230 proxyCreds.authorize(request); |
| 1231 } | 1231 } |
| 1232 } | 1232 } |
| 1233 if (uri.userInfo != null && !uri.userInfo.isEmpty) { | 1233 if (uri.userInfo != null && !uri.userInfo.isEmpty) { |
| 1234 // If the URL contains user information use that for basic | 1234 // If the URL contains user information use that for basic |
| 1235 // authorization. | 1235 // authorization. |
| 1236 String auth = | 1236 String auth = |
| 1237 _CryptoUtils.bytesToBase64(_encodeString(uri.userInfo)); | 1237 _CryptoUtils.bytesToBase64(UTF8.encode(uri.userInfo)); |
| 1238 request.headers.set(HttpHeaders.AUTHORIZATION, "Basic $auth"); | 1238 request.headers.set(HttpHeaders.AUTHORIZATION, "Basic $auth"); |
| 1239 } else { | 1239 } else { |
| 1240 // Look for credentials. | 1240 // Look for credentials. |
| 1241 creds = _httpClient._findCredentials(uri); | 1241 creds = _httpClient._findCredentials(uri); |
| 1242 if (creds != null) { | 1242 if (creds != null) { |
| 1243 creds.authorize(request); | 1243 creds.authorize(request); |
| 1244 } | 1244 } |
| 1245 } | 1245 } |
| 1246 // Start sending the request (lazy, delayed until the user provides | 1246 // Start sending the request (lazy, delayed until the user provides |
| 1247 // data). | 1247 // data). |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 Future<_HttpClientConnection> createProxyTunnel(host, port, proxy, callback) { | 1338 Future<_HttpClientConnection> createProxyTunnel(host, port, proxy, callback) { |
| 1339 _HttpClientRequest request = | 1339 _HttpClientRequest request = |
| 1340 send(new Uri(host: host, port: port), | 1340 send(new Uri(host: host, port: port), |
| 1341 port, | 1341 port, |
| 1342 "CONNECT", | 1342 "CONNECT", |
| 1343 proxy); | 1343 proxy); |
| 1344 if (proxy.isAuthenticated) { | 1344 if (proxy.isAuthenticated) { |
| 1345 // If the proxy configuration contains user information use that | 1345 // If the proxy configuration contains user information use that |
| 1346 // for proxy basic authorization. | 1346 // for proxy basic authorization. |
| 1347 String auth = _CryptoUtils.bytesToBase64( | 1347 String auth = _CryptoUtils.bytesToBase64( |
| 1348 _encodeString("${proxy.username}:${proxy.password}")); | 1348 UTF8.encode("${proxy.username}:${proxy.password}")); |
| 1349 request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, "Basic $auth"); | 1349 request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, "Basic $auth"); |
| 1350 } | 1350 } |
| 1351 return request.close() | 1351 return request.close() |
| 1352 .then((response) { | 1352 .then((response) { |
| 1353 if (response.statusCode != HttpStatus.OK) { | 1353 if (response.statusCode != HttpStatus.OK) { |
| 1354 throw "Proxy failed to establish tunnel " | 1354 throw "Proxy failed to establish tunnel " |
| 1355 "(${response.statusCode} ${response.reasonPhrase})"; | 1355 "(${response.statusCode} ${response.reasonPhrase})"; |
| 1356 } | 1356 } |
| 1357 var socket = response._httpRequest._httpClientConnection._socket; | 1357 var socket = response._httpRequest._httpClientConnection._socket; |
| 1358 return SecureSocket.secure( | 1358 return SecureSocket.secure( |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2263 _Credentials(this.credentials, this.realm) { | 2263 _Credentials(this.credentials, this.realm) { |
| 2264 if (credentials.scheme == _AuthenticationScheme.DIGEST) { | 2264 if (credentials.scheme == _AuthenticationScheme.DIGEST) { |
| 2265 // Calculate the H(A1) value once. There is no mentioning of | 2265 // Calculate the H(A1) value once. There is no mentioning of |
| 2266 // username/password encoding in RFC 2617. However there is an | 2266 // username/password encoding in RFC 2617. However there is an |
| 2267 // open draft for adding an additional accept-charset parameter to | 2267 // open draft for adding an additional accept-charset parameter to |
| 2268 // the WWW-Authenticate and Proxy-Authenticate headers, see | 2268 // the WWW-Authenticate and Proxy-Authenticate headers, see |
| 2269 // http://tools.ietf.org/html/draft-reschke-basicauth-enc-06. For | 2269 // http://tools.ietf.org/html/draft-reschke-basicauth-enc-06. For |
| 2270 // now always use UTF-8 encoding. | 2270 // now always use UTF-8 encoding. |
| 2271 _HttpClientDigestCredentials creds = credentials; | 2271 _HttpClientDigestCredentials creds = credentials; |
| 2272 var hasher = new _MD5(); | 2272 var hasher = new _MD5(); |
| 2273 hasher.add(_encodeString(creds.username)); | 2273 hasher.add(UTF8.encode(creds.username)); |
| 2274 hasher.add([_CharCode.COLON]); | 2274 hasher.add([_CharCode.COLON]); |
| 2275 hasher.add(realm.codeUnits); | 2275 hasher.add(realm.codeUnits); |
| 2276 hasher.add([_CharCode.COLON]); | 2276 hasher.add([_CharCode.COLON]); |
| 2277 hasher.add(_encodeString(creds.password)); | 2277 hasher.add(UTF8.encode(creds.password)); |
| 2278 ha1 = _CryptoUtils.bytesToHex(hasher.close()); | 2278 ha1 = _CryptoUtils.bytesToHex(hasher.close()); |
| 2279 } | 2279 } |
| 2280 } | 2280 } |
| 2281 | 2281 |
| 2282 _AuthenticationScheme get scheme => credentials.scheme; | 2282 _AuthenticationScheme get scheme => credentials.scheme; |
| 2283 | 2283 |
| 2284 void authorize(HttpClientRequest request); | 2284 void authorize(HttpClientRequest request); |
| 2285 } | 2285 } |
| 2286 | 2286 |
| 2287 class _SiteCredentials extends _Credentials { | 2287 class _SiteCredentials extends _Credentials { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2356 _AuthenticationScheme get scheme => _AuthenticationScheme.BASIC; | 2356 _AuthenticationScheme get scheme => _AuthenticationScheme.BASIC; |
| 2357 | 2357 |
| 2358 String authorization() { | 2358 String authorization() { |
| 2359 // There is no mentioning of username/password encoding in RFC | 2359 // There is no mentioning of username/password encoding in RFC |
| 2360 // 2617. However there is an open draft for adding an additional | 2360 // 2617. However there is an open draft for adding an additional |
| 2361 // accept-charset parameter to the WWW-Authenticate and | 2361 // accept-charset parameter to the WWW-Authenticate and |
| 2362 // Proxy-Authenticate headers, see | 2362 // Proxy-Authenticate headers, see |
| 2363 // http://tools.ietf.org/html/draft-reschke-basicauth-enc-06. For | 2363 // http://tools.ietf.org/html/draft-reschke-basicauth-enc-06. For |
| 2364 // now always use UTF-8 encoding. | 2364 // now always use UTF-8 encoding. |
| 2365 String auth = | 2365 String auth = |
| 2366 _CryptoUtils.bytesToBase64(_encodeString("$username:$password")); | 2366 _CryptoUtils.bytesToBase64(UTF8.encode("$username:$password")); |
| 2367 return "Basic $auth"; | 2367 return "Basic $auth"; |
| 2368 } | 2368 } |
| 2369 | 2369 |
| 2370 void authorize(_Credentials _, HttpClientRequest request) { | 2370 void authorize(_Credentials _, HttpClientRequest request) { |
| 2371 request.headers.set(HttpHeaders.AUTHORIZATION, authorization()); | 2371 request.headers.set(HttpHeaders.AUTHORIZATION, authorization()); |
| 2372 } | 2372 } |
| 2373 | 2373 |
| 2374 void authorizeProxy(_ProxyCredentials _, HttpClientRequest request) { | 2374 void authorizeProxy(_ProxyCredentials _, HttpClientRequest request) { |
| 2375 request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, authorization()); | 2375 request.headers.set(HttpHeaders.PROXY_AUTHORIZATION, authorization()); |
| 2376 } | 2376 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2466 final Uri location; | 2466 final Uri location; |
| 2467 } | 2467 } |
| 2468 | 2468 |
| 2469 String _getHttpVersion() { | 2469 String _getHttpVersion() { |
| 2470 var version = Platform.version; | 2470 var version = Platform.version; |
| 2471 // Only include major and minor version numbers. | 2471 // Only include major and minor version numbers. |
| 2472 int index = version.indexOf('.', version.indexOf('.') + 1); | 2472 int index = version.indexOf('.', version.indexOf('.') + 1); |
| 2473 version = version.substring(0, index); | 2473 version = version.substring(0, index); |
| 2474 return 'Dart/$version (dart:io)'; | 2474 return 'Dart/$version (dart:io)'; |
| 2475 } | 2475 } |
| OLD | NEW |