| 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 const int _OUTGOING_BUFFER_SIZE = 8 * 1024; | 7 const int _OUTGOING_BUFFER_SIZE = 8 * 1024; |
| 8 | 8 |
| 9 class _HttpIncoming extends Stream<List<int>> { | 9 class _HttpIncoming extends Stream<List<int>> { |
| 10 final int _transferLength; | 10 final int _transferLength; |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 | 784 |
| 785 void _onError(error, StackTrace stackTrace) { | 785 void _onError(error, StackTrace stackTrace) { |
| 786 _responseCompleter.completeError(error, stackTrace); | 786 _responseCompleter.completeError(error, stackTrace); |
| 787 } | 787 } |
| 788 | 788 |
| 789 // Generate the request URI based on the method and proxy. | 789 // Generate the request URI based on the method and proxy. |
| 790 String _requestUri() { | 790 String _requestUri() { |
| 791 // Generate the request URI starting from the path component. | 791 // Generate the request URI starting from the path component. |
| 792 String uriStartingFromPath() { | 792 String uriStartingFromPath() { |
| 793 String result = uri.path; | 793 String result = uri.path; |
| 794 if (result.length == 0) result = "/"; | 794 if (result.isEmpty) result = "/"; |
| 795 if (uri.query != "") { | 795 if (uri.hasQuery) { |
| 796 if (uri.fragment != "") { | 796 result = "${result}?${uri.query}"; |
| 797 result = "${result}?${uri.query}#${uri.fragment}"; | |
| 798 } else { | |
| 799 result = "${result}?${uri.query}"; | |
| 800 } | |
| 801 } | 797 } |
| 802 return result; | 798 return result; |
| 803 } | 799 } |
| 804 | 800 |
| 805 if (_proxy.isDirect) { | 801 if (_proxy.isDirect) { |
| 806 return uriStartingFromPath(); | 802 return uriStartingFromPath(); |
| 807 } else { | 803 } else { |
| 808 if (method == "CONNECT") { | 804 if (method == "CONNECT") { |
| 809 // For the connect method the request URI is the host:port of | 805 // For the connect method the request URI is the host:port of |
| 810 // the requested destination of the tunnel (see RFC 2817 | 806 // the requested destination of the tunnel (see RFC 2817 |
| 811 // section 5.2) | 807 // section 5.2) |
| 812 return "${uri.host}:${uri.port}"; | 808 return "${uri.host}:${uri.port}"; |
| 813 } else { | 809 } else { |
| 814 if (_httpClientConnection._proxyTunnel) { | 810 if (_httpClientConnection._proxyTunnel) { |
| 815 return uriStartingFromPath(); | 811 return uriStartingFromPath(); |
| 816 } else { | 812 } else { |
| 817 return uri.toString(); | 813 return uri.removeFragment().toString(); |
| 818 } | 814 } |
| 819 } | 815 } |
| 820 } | 816 } |
| 821 } | 817 } |
| 822 | 818 |
| 823 void _writeHeader() { | 819 void _writeHeader() { |
| 824 Uint8List buffer = new Uint8List(_OUTGOING_BUFFER_SIZE); | 820 Uint8List buffer = new Uint8List(_OUTGOING_BUFFER_SIZE); |
| 825 int offset = 0; | 821 int offset = 0; |
| 826 | 822 |
| 827 void write(List<int> bytes) { | 823 void write(List<int> bytes) { |
| (...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1695 String host, | 1691 String host, |
| 1696 int port)) { | 1692 int port)) { |
| 1697 _badCertificateCallback = callback; | 1693 _badCertificateCallback = callback; |
| 1698 } | 1694 } |
| 1699 | 1695 |
| 1700 | 1696 |
| 1701 Future<HttpClientRequest> open(String method, | 1697 Future<HttpClientRequest> open(String method, |
| 1702 String host, | 1698 String host, |
| 1703 int port, | 1699 int port, |
| 1704 String path) { | 1700 String path) { |
| 1705 Uri uri = new Uri(scheme: "http", host: host, port: port).resolve(path); | 1701 const int hashMark = 0x23; |
| 1706 // TODO(sgjesse): The path set here can contain both query and | 1702 const int questionMark = 0x3f; |
| 1707 // fragment. They should be cracked and set correctly. | 1703 int fragmentStart = path.length; |
| 1704 int queryStart = path.length; |
| 1705 for (int i = path.length - 1; i >= 0; i--) { |
| 1706 var char = path.codeUnitAt(i); |
| 1707 if (char == hashMark) { |
| 1708 fragmentStart = i; |
| 1709 queryStart = i; |
| 1710 } else if (char == questionMark) { |
| 1711 queryStart = i; |
| 1712 } |
| 1713 } |
| 1714 String query = null; |
| 1715 if (queryStart < fragmentStart) { |
| 1716 query = path.substring(queryStart + 1, fragmentStart); |
| 1717 path = path.substring(0, queryStart); |
| 1718 } |
| 1719 Uri uri = new Uri(scheme: "http", host: host, port: port, |
| 1720 path: path, query: query); |
| 1708 return _openUrl(method, uri); | 1721 return _openUrl(method, uri); |
| 1709 } | 1722 } |
| 1710 | 1723 |
| 1711 Future<HttpClientRequest> openUrl(String method, Uri url) { | 1724 Future<HttpClientRequest> openUrl(String method, Uri url) { |
| 1712 return _openUrl(method, url); | 1725 return _openUrl(method, url); |
| 1713 } | 1726 } |
| 1714 | 1727 |
| 1715 Future<HttpClientRequest> get(String host, int port, String path) | 1728 Future<HttpClientRequest> get(String host, int port, String path) |
| 1716 => open("get", host, port, path); | 1729 => open("get", host, port, path); |
| 1717 | 1730 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1765 | 1778 |
| 1766 void addProxyCredentials(String host, | 1779 void addProxyCredentials(String host, |
| 1767 int port, | 1780 int port, |
| 1768 String realm, | 1781 String realm, |
| 1769 HttpClientCredentials cr) => | 1782 HttpClientCredentials cr) => |
| 1770 _proxyCredentials.add(new _ProxyCredentials(host, port, realm, cr)); | 1783 _proxyCredentials.add(new _ProxyCredentials(host, port, realm, cr)); |
| 1771 | 1784 |
| 1772 set findProxy(String f(Uri uri)) => _findProxy = f; | 1785 set findProxy(String f(Uri uri)) => _findProxy = f; |
| 1773 | 1786 |
| 1774 Future<HttpClientRequest> _openUrl(String method, Uri uri) { | 1787 Future<HttpClientRequest> _openUrl(String method, Uri uri) { |
| 1788 // Ignore any fragments on the request URI. |
| 1789 uri = uri.removeFragment(); |
| 1790 |
| 1775 if (method == null) { | 1791 if (method == null) { |
| 1776 throw new ArgumentError(method); | 1792 throw new ArgumentError(method); |
| 1777 } | 1793 } |
| 1778 if (method != "CONNECT") { | 1794 if (method != "CONNECT") { |
| 1779 if (uri.host.isEmpty) { | 1795 if (uri.host.isEmpty) { |
| 1780 throw new ArgumentError("No host specified in URI $uri"); | 1796 throw new ArgumentError("No host specified in URI $uri"); |
| 1781 } else if (uri.scheme != "http" && uri.scheme != "https") { | 1797 } else if (uri.scheme != "http" && uri.scheme != "https") { |
| 1782 throw new ArgumentError( | 1798 throw new ArgumentError( |
| 1783 "Unsupported scheme '${uri.scheme}' in URI $uri"); | 1799 "Unsupported scheme '${uri.scheme}' in URI $uri"); |
| 1784 } | 1800 } |
| (...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2832 const _RedirectInfo(this.statusCode, this.method, this.location); | 2848 const _RedirectInfo(this.statusCode, this.method, this.location); |
| 2833 } | 2849 } |
| 2834 | 2850 |
| 2835 String _getHttpVersion() { | 2851 String _getHttpVersion() { |
| 2836 var version = Platform.version; | 2852 var version = Platform.version; |
| 2837 // Only include major and minor version numbers. | 2853 // Only include major and minor version numbers. |
| 2838 int index = version.indexOf('.', version.indexOf('.') + 1); | 2854 int index = version.indexOf('.', version.indexOf('.') + 1); |
| 2839 version = version.substring(0, index); | 2855 version = version.substring(0, index); |
| 2840 return 'Dart/$version (dart:io)'; | 2856 return 'Dart/$version (dart:io)'; |
| 2841 } | 2857 } |
| OLD | NEW |