Chromium Code Reviews| 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 _HttpRequestResponseBase { | 5 class _HttpRequestResponseBase { |
| 6 _HttpRequestResponseBase(_HttpConnectionBase this._httpConnection) | 6 _HttpRequestResponseBase(_HttpConnectionBase this._httpConnection) |
| 7 : _contentLength = -1, | 7 : _contentLength = -1, |
| 8 _keepAlive = false, | 8 _keepAlive = false, |
| 9 _headers = new Map(); | 9 _headers = new Map(); |
| 10 | 10 |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 if (_onError != null) _onError(errorMessage); | 619 if (_onError != null) _onError(errorMessage); |
| 620 } | 620 } |
| 621 connection.onError = onError; | 621 connection.onError = onError; |
| 622 } | 622 } |
| 623 | 623 |
| 624 _connections = new Set<_HttpConnection>(); | 624 _connections = new Set<_HttpConnection>(); |
| 625 _server = new ServerSocket(host, port, backlog); | 625 _server = new ServerSocket(host, port, backlog); |
| 626 _server.onConnection = onConnection; | 626 _server.onConnection = onConnection; |
| 627 } | 627 } |
| 628 | 628 |
| 629 void close() => _server.close(); | 629 void close() { |
| 630 _server.close(); | |
| 631 for (_HttpConnection connection in _connections) { | |
| 632 connection._socket.close(); | |
| 633 } | |
| 634 } | |
| 635 | |
| 630 int get port() => _server.port; | 636 int get port() => _server.port; |
| 631 | 637 |
| 632 void set onError(void handler(String errorMessage)) { | 638 void set onError(void handler(String errorMessage)) { |
| 633 _onError = handler; | 639 _onError = handler; |
| 634 } | 640 } |
| 635 | 641 |
| 636 void set onRequest(void handler(HttpRequest, HttpResponse)) { | 642 void set onRequest(void handler(HttpRequest, HttpResponse)) { |
| 637 _onRequest = handler; | 643 _onRequest = handler; |
| 638 } | 644 } |
| 639 | 645 |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 _httpParser.requestStart = | 886 _httpParser.requestStart = |
| 881 (method, uri) => _onRequestStart(method, uri); | 887 (method, uri) => _onRequestStart(method, uri); |
| 882 _httpParser.responseStart = | 888 _httpParser.responseStart = |
| 883 (statusCode, reasonPhrase) => | 889 (statusCode, reasonPhrase) => |
| 884 _onResponseStart(statusCode, reasonPhrase); | 890 _onResponseStart(statusCode, reasonPhrase); |
| 885 _httpParser.headerReceived = | 891 _httpParser.headerReceived = |
| 886 (name, value) => _onHeaderReceived(name, value); | 892 (name, value) => _onHeaderReceived(name, value); |
| 887 _httpParser.headersComplete = () => _onHeadersComplete(); | 893 _httpParser.headersComplete = () => _onHeadersComplete(); |
| 888 _httpParser.dataReceived = (data) => _onDataReceived(data); | 894 _httpParser.dataReceived = (data) => _onDataReceived(data); |
| 889 _httpParser.dataEnd = () => _onDataEnd(); | 895 _httpParser.dataEnd = () => _onDataEnd(); |
| 896 onDisconnect = _onDisconnected; | |
| 890 } | 897 } |
| 891 | 898 |
| 892 HttpClientRequest open(String method, String uri) { | 899 HttpClientRequest open(String method, String uri) { |
| 893 _request = new _HttpClientRequest(method, uri, this); | 900 _request = new _HttpClientRequest(method, uri, this); |
| 894 _request.keepAlive = true; | 901 _request.keepAlive = true; |
| 895 _response = new _HttpClientResponse(this); | 902 _response = new _HttpClientResponse(this); |
| 896 return _request; | 903 return _request; |
| 897 } | 904 } |
| 898 | 905 |
| 899 void _onRequestStart(String method, String uri) { | 906 void _onRequestStart(String method, String uri) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 910 | 917 |
| 911 void _onHeadersComplete() { | 918 void _onHeadersComplete() { |
| 912 _response._onHeadersComplete(); | 919 _response._onHeadersComplete(); |
| 913 } | 920 } |
| 914 | 921 |
| 915 void _onDataReceived(List<int> data) { | 922 void _onDataReceived(List<int> data) { |
| 916 _response._onDataReceived(data); | 923 _response._onDataReceived(data); |
| 917 } | 924 } |
| 918 | 925 |
| 919 void _onDataEnd() { | 926 void _onDataEnd() { |
| 927 onDisconnect = null; | |
| 920 if (_response.headers["connection"] == "close") { | 928 if (_response.headers["connection"] == "close") { |
| 921 _socket.close(); | 929 _socket.close(); |
| 922 } else { | 930 } else { |
| 923 _client._returnSocketConnection(_socketConn); | 931 _client._returnSocketConnection(_socketConn); |
| 924 _socket = null; | 932 _socket = null; |
| 925 _socketConn = null; | 933 _socketConn = null; |
| 926 } | 934 } |
| 927 _response._onDataEnd(); | 935 _response._onDataEnd(); |
| 928 } | 936 } |
| 929 | 937 |
| 930 void set onRequest(void handler(HttpClientRequest request)) { | 938 void set onRequest(void handler(HttpClientRequest request)) { |
| 931 _onRequest = handler; | 939 _onRequest = handler; |
| 932 } | 940 } |
| 933 | 941 |
| 934 void set onResponse(void handler(HttpClientResponse response)) { | 942 void set onResponse(void handler(HttpClientResponse response)) { |
| 935 _onResponse = handler; | 943 _onResponse = handler; |
| 936 } | 944 } |
| 937 | 945 |
| 946 void _onDisconnected() { | |
|
Søren Gjesse
2012/03/14 09:26:59
We probably need to handle this slightly different
Anders Johnsen
2012/03/14 09:34:43
My initial understanding was that _onDataEnd was c
Søren Gjesse
2012/03/14 10:03:30
You are right this should be fixed in the HTTP par
Anders Johnsen
2012/03/14 10:08:54
Want me to make it a part of this cl, or is it som
| |
| 947 if (_onErrorCallback !== null) { | |
| 948 _onErrorCallback( | |
| 949 new HttpException("Client disconnected before response was sent.")); | |
|
Søren Gjesse
2012/03/14 09:26:59
"was sent" should probably be "was received".
Anders Johnsen
2012/03/14 09:34:43
Done.
| |
| 950 } | |
| 951 } | |
| 952 | |
| 953 | |
| 938 Function _onRequest; | 954 Function _onRequest; |
| 939 Function _onResponse; | 955 Function _onResponse; |
| 940 | 956 |
| 941 _HttpClient _client; | 957 _HttpClient _client; |
| 942 _SocketConnection _socketConn; | 958 _SocketConnection _socketConn; |
| 943 HttpClientRequest _request; | 959 HttpClientRequest _request; |
| 944 HttpClientResponse _response; | 960 HttpClientResponse _response; |
| 945 | 961 |
| 946 // Callbacks. | 962 // Callbacks. |
| 947 var requestReceived; | 963 var requestReceived; |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1138 _onError = callback; | 1154 _onError = callback; |
| 1139 } | 1155 } |
| 1140 | 1156 |
| 1141 Function _onOpen; | 1157 Function _onOpen; |
| 1142 Function _onError; | 1158 Function _onError; |
| 1143 Map<String, Queue<_SocketConnection>> _openSockets; | 1159 Map<String, Queue<_SocketConnection>> _openSockets; |
| 1144 Set<_SocketConnection> _activeSockets; | 1160 Set<_SocketConnection> _activeSockets; |
| 1145 Timer _evictionTimer; | 1161 Timer _evictionTimer; |
| 1146 bool _shutdown; // Has this HTTP client been shutdown? | 1162 bool _shutdown; // Has this HTTP client been shutdown? |
| 1147 } | 1163 } |
| OLD | NEW |