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 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 return _getConnection(uri.host, port, proxyConf, isSecure) | 1561 return _getConnection(uri.host, port, proxyConf, isSecure) |
1562 .then(send); | 1562 .then(send); |
1563 } | 1563 } |
1564 return send(info); | 1564 return send(info); |
1565 }); | 1565 }); |
1566 } | 1566 } |
1567 | 1567 |
1568 Future<HttpClientRequest> _openUrlFromRequest(String method, | 1568 Future<HttpClientRequest> _openUrlFromRequest(String method, |
1569 Uri uri, | 1569 Uri uri, |
1570 _HttpClientRequest previous) { | 1570 _HttpClientRequest previous) { |
1571 var u = uri; | |
1572 // If the new URI is relative (to either '/' or some sub-path), | 1571 // If the new URI is relative (to either '/' or some sub-path), |
1573 // construct a full URI from the previous one. | 1572 // construct a full URI from the previous one. |
1574 // See http://tools.ietf.org/html/rfc3986#section-4.2 | 1573 URI resolved = previous.uri.resolveUri(uri); |
1575 replaceComponents({scheme, host, port, path}) { | 1574 return openUrl(method, resolved).then((_HttpClientRequest request) { |
1576 uri = new Uri( | |
1577 scheme: scheme != null ? scheme : uri.scheme, | |
1578 host: host != null ? host : uri.host, | |
1579 port: port != null ? port : uri.port, | |
1580 path: path != null ? path : uri.path, | |
1581 query: uri.query, | |
1582 fragment: uri.fragment); | |
1583 } | |
1584 | |
1585 var scheme; | |
1586 var host; | |
1587 var port; | |
1588 var path; | |
1589 if (uri.host.isEmpty) { | |
1590 host = previous.uri.host; | |
1591 port = previous.uri.port; | |
1592 } | |
1593 if (uri.scheme.isEmpty) { | |
1594 scheme = previous.uri.scheme; | |
1595 } | |
1596 if (!uri.path.startsWith('/')) { | |
1597 var absolute = new _Path.raw(previous.uri.path).directoryPath; | |
1598 absolute = absolute.join(new _Path.raw(u.path)); | |
1599 path = absolute.canonicalize().toString(); | |
1600 } | |
1601 replaceComponents(scheme: scheme, host: host, port: port, path: path); | |
1602 return openUrl(method, uri).then((_HttpClientRequest request) { | |
1603 // Only follow redirects if initial request did. | 1575 // Only follow redirects if initial request did. |
1604 request.followRedirects = previous.followRedirects; | 1576 request.followRedirects = previous.followRedirects; |
1605 // Allow same number of redirects. | 1577 // Allow same number of redirects. |
1606 request.maxRedirects = previous.maxRedirects; | 1578 request.maxRedirects = previous.maxRedirects; |
1607 // Copy headers. | 1579 // Copy headers. |
1608 for (var header in previous.headers._headers.keys) { | 1580 for (var header in previous.headers._headers.keys) { |
1609 if (request.headers[header] == null) { | 1581 if (request.headers[header] == null) { |
1610 request.headers.set(header, previous.headers[header]); | 1582 request.headers.set(header, previous.headers[header]); |
1611 } | 1583 } |
1612 } | 1584 } |
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2475 final Uri location; | 2447 final Uri location; |
2476 } | 2448 } |
2477 | 2449 |
2478 String _getHttpVersion() { | 2450 String _getHttpVersion() { |
2479 var version = Platform.version; | 2451 var version = Platform.version; |
2480 // Only include major and minor version numbers. | 2452 // Only include major and minor version numbers. |
2481 int index = version.indexOf('.', version.indexOf('.') + 1); | 2453 int index = version.indexOf('.', version.indexOf('.') + 1); |
2482 version = version.substring(0, index); | 2454 version = version.substring(0, index); |
2483 return 'Dart/$version (dart:io)'; | 2455 return 'Dart/$version (dart:io)'; |
2484 } | 2456 } |
OLD | NEW |