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 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 List<String> headerValues = headers["cookie"]; | 848 List<String> headerValues = headers["cookie"]; |
849 if (headerValues != null) { | 849 if (headerValues != null) { |
850 headerValues.forEach((headerValue) => _parseCookieString(headerValue)); | 850 headerValues.forEach((headerValue) => _parseCookieString(headerValue)); |
851 } | 851 } |
852 return _cookies; | 852 return _cookies; |
853 } | 853 } |
854 | 854 |
855 InputStream get inputStream { | 855 InputStream get inputStream { |
856 if (_inputStream == null) { | 856 if (_inputStream == null) { |
857 _inputStream = new _HttpInputStream(this); | 857 _inputStream = new _HttpInputStream(this); |
858 _inputStream._streamMarkedClosed = _dataEndCalled; | |
859 } | 858 } |
860 return _inputStream; | 859 return _inputStream; |
861 } | 860 } |
862 | 861 |
863 String get protocolVersion => _protocolVersion; | 862 String get protocolVersion => _protocolVersion; |
864 | 863 |
865 HttpSession session([init(HttpSession session)]) { | 864 HttpSession session([init(HttpSession session)]) { |
866 if (_session != null) { | 865 if (_session != null) { |
867 // It's already mapped, use it. | 866 // It's already mapped, use it. |
868 return _session; | 867 return _session; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 _headers._mutable = false; | 905 _headers._mutable = false; |
907 _buffer = new _BufferList(); | 906 _buffer = new _BufferList(); |
908 } | 907 } |
909 | 908 |
910 void _onDataReceived(List<int> data) { | 909 void _onDataReceived(List<int> data) { |
911 _buffer.add(data); | 910 _buffer.add(data); |
912 if (_inputStream != null) _inputStream._dataReceived(); | 911 if (_inputStream != null) _inputStream._dataReceived(); |
913 } | 912 } |
914 | 913 |
915 void _onDataEnd() { | 914 void _onDataEnd() { |
916 if (_inputStream != null) _inputStream._closeReceived(); | 915 if (_inputStream != null) { |
917 _dataEndCalled = true; | 916 _inputStream._closeReceived(); |
| 917 } else { |
| 918 inputStream._streamMarkedClosed = true; |
| 919 } |
918 } | 920 } |
919 | 921 |
920 // Escaped characters in uri are expected to have been parsed. | 922 // Escaped characters in uri are expected to have been parsed. |
921 void _parseRequestUri(String uri) { | 923 void _parseRequestUri(String uri) { |
922 int position; | 924 int position; |
923 position = uri.indexOf("?", 0); | 925 position = uri.indexOf("?", 0); |
924 if (position == -1) { | 926 if (position == -1) { |
925 _path = _HttpUtils.decodeUrlEncodedString(_uri); | 927 _path = _HttpUtils.decodeUrlEncodedString(_uri); |
926 _queryString = null; | 928 _queryString = null; |
927 _queryParameters = new Map(); | 929 _queryParameters = new Map(); |
(...skipping 22 matching lines...) Expand all Loading... |
950 _streamErrorHandler = callback; | 952 _streamErrorHandler = callback; |
951 } | 953 } |
952 | 954 |
953 String _method; | 955 String _method; |
954 String _uri; | 956 String _uri; |
955 String _path; | 957 String _path; |
956 String _queryString; | 958 String _queryString; |
957 Map<String, String> _queryParameters; | 959 Map<String, String> _queryParameters; |
958 _HttpInputStream _inputStream; | 960 _HttpInputStream _inputStream; |
959 _BufferList _buffer; | 961 _BufferList _buffer; |
960 bool _dataEndCalled = false; | |
961 Function _streamErrorHandler; | 962 Function _streamErrorHandler; |
962 _HttpSession _session; | 963 _HttpSession _session; |
963 } | 964 } |
964 | 965 |
965 | 966 |
966 // HTTP response object for sending a HTTP response. | 967 // HTTP response object for sending a HTTP response. |
967 class _HttpResponse extends _HttpRequestResponseBase implements HttpResponse { | 968 class _HttpResponse extends _HttpRequestResponseBase implements HttpResponse { |
968 _HttpResponse(_HttpConnection httpConnection) | 969 _HttpResponse(_HttpConnection httpConnection) |
969 : super(httpConnection), | 970 : super(httpConnection), |
970 _statusCode = HttpStatus.OK; | 971 _statusCode = HttpStatus.OK; |
(...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1762 values.forEach((value) { | 1763 values.forEach((value) { |
1763 _cookies.add(new Cookie.fromSetCookieValue(value)); | 1764 _cookies.add(new Cookie.fromSetCookieValue(value)); |
1764 }); | 1765 }); |
1765 } | 1766 } |
1766 return _cookies; | 1767 return _cookies; |
1767 } | 1768 } |
1768 | 1769 |
1769 InputStream get inputStream { | 1770 InputStream get inputStream { |
1770 if (_inputStream == null) { | 1771 if (_inputStream == null) { |
1771 _inputStream = new _HttpInputStream(this); | 1772 _inputStream = new _HttpInputStream(this); |
1772 _inputStream._streamMarkedClosed = _dataEndCalled; | |
1773 } | 1773 } |
1774 return _inputStream; | 1774 return _inputStream; |
1775 } | 1775 } |
1776 | 1776 |
1777 void _onRequestStart(String method, String uri, String version) { | 1777 void _onRequestStart(String method, String uri, String version) { |
1778 // TODO(sgjesse): Error handling | 1778 // TODO(sgjesse): Error handling |
1779 } | 1779 } |
1780 | 1780 |
1781 void _onResponseStart(int statusCode, String reasonPhrase, String version) { | 1781 void _onResponseStart(int statusCode, String reasonPhrase, String version) { |
1782 _statusCode = statusCode; | 1782 _statusCode = statusCode; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1900 } | 1900 } |
1901 } | 1901 } |
1902 | 1902 |
1903 void _onDataReceived(List<int> data) { | 1903 void _onDataReceived(List<int> data) { |
1904 _buffer.add(data); | 1904 _buffer.add(data); |
1905 if (_inputStream != null) _inputStream._dataReceived(); | 1905 if (_inputStream != null) _inputStream._dataReceived(); |
1906 } | 1906 } |
1907 | 1907 |
1908 void _onDataEnd() { | 1908 void _onDataEnd() { |
1909 _connection._responseDone(); | 1909 _connection._responseDone(); |
1910 if (_inputStream != null) _inputStream._closeReceived(); | 1910 if (_inputStream != null) { |
1911 _dataEndCalled = true; | 1911 _inputStream._closeReceived(); |
| 1912 } else { |
| 1913 inputStream._streamMarkedClosed = true; |
| 1914 } |
1912 } | 1915 } |
1913 | 1916 |
1914 // Delegate functions for the HttpInputStream implementation. | 1917 // Delegate functions for the HttpInputStream implementation. |
1915 int _streamAvailable() { | 1918 int _streamAvailable() { |
1916 return _buffer.length; | 1919 return _buffer.length; |
1917 } | 1920 } |
1918 | 1921 |
1919 List<int> _streamRead(int bytesToRead) { | 1922 List<int> _streamRead(int bytesToRead) { |
1920 return _buffer.readBytes(bytesToRead); | 1923 return _buffer.readBytes(bytesToRead); |
1921 } | 1924 } |
1922 | 1925 |
1923 int _streamReadInto(List<int> buffer, int offset, int len) { | 1926 int _streamReadInto(List<int> buffer, int offset, int len) { |
1924 List<int> data = _buffer.readBytes(len); | 1927 List<int> data = _buffer.readBytes(len); |
1925 buffer.setRange(offset, data.length, data); | 1928 buffer.setRange(offset, data.length, data); |
1926 return data.length; | 1929 return data.length; |
1927 } | 1930 } |
1928 | 1931 |
1929 void _streamSetErrorHandler(callback(e)) { | 1932 void _streamSetErrorHandler(callback(e)) { |
1930 _streamErrorHandler = callback; | 1933 _streamErrorHandler = callback; |
1931 } | 1934 } |
1932 | 1935 |
1933 int _statusCode; | 1936 int _statusCode; |
1934 String _reasonPhrase; | 1937 String _reasonPhrase; |
1935 | 1938 |
1936 _HttpClientConnection _connection; | 1939 _HttpClientConnection _connection; |
1937 _HttpInputStream _inputStream; | 1940 _HttpInputStream _inputStream; |
1938 _BufferList _buffer; | 1941 _BufferList _buffer; |
1939 bool _dataEndCalled = false; | |
1940 | 1942 |
1941 Function _streamErrorHandler; | 1943 Function _streamErrorHandler; |
1942 } | 1944 } |
1943 | 1945 |
1944 | 1946 |
1945 class _HttpClientConnection | 1947 class _HttpClientConnection |
1946 extends _HttpConnectionBase implements HttpClientConnection { | 1948 extends _HttpConnectionBase implements HttpClientConnection { |
1947 static const int NONE = 0; | 1949 static const int NONE = 0; |
1948 static const int REQUEST_DONE = 1; | 1950 static const int REQUEST_DONE = 1; |
1949 static const int RESPONSE_DONE = 2; | 1951 static const int RESPONSE_DONE = 2; |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2646 | 2648 |
2647 | 2649 |
2648 class _RedirectInfo implements RedirectInfo { | 2650 class _RedirectInfo implements RedirectInfo { |
2649 const _RedirectInfo(int this.statusCode, | 2651 const _RedirectInfo(int this.statusCode, |
2650 String this.method, | 2652 String this.method, |
2651 Uri this.location); | 2653 Uri this.location); |
2652 final int statusCode; | 2654 final int statusCode; |
2653 final String method; | 2655 final String method; |
2654 final Uri location; | 2656 final Uri location; |
2655 } | 2657 } |
OLD | NEW |