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 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 void set onError(void callback(e)) { | 1195 void set onError(void callback(e)) { |
1196 _requestOrResponse._streamSetErrorHandler(callback); | 1196 _requestOrResponse._streamSetErrorHandler(callback); |
1197 } | 1197 } |
1198 | 1198 |
1199 _HttpRequestResponseBase _requestOrResponse; | 1199 _HttpRequestResponseBase _requestOrResponse; |
1200 } | 1200 } |
1201 | 1201 |
1202 | 1202 |
1203 class _HttpConnectionBase { | 1203 class _HttpConnectionBase { |
1204 _HttpConnectionBase() : _sendBuffers = new Queue(), | 1204 _HttpConnectionBase() : _sendBuffers = new Queue(), |
1205 _httpParser = new _HttpParser() { | 1205 _httpParser = new _HttpParser(), |
1206 _hashCode = _nextHashCode; | 1206 hashCode = _nextHashCode { |
1207 _nextHashCode = (_nextHashCode + 1) & 0xFFFFFFF; | 1207 _nextHashCode = (_nextHashCode + 1) & 0xFFFFFFF; |
1208 } | 1208 } |
1209 | 1209 |
1210 void _connectionEstablished(Socket socket) { | 1210 void _connectionEstablished(Socket socket) { |
1211 _socket = socket; | 1211 _socket = socket; |
1212 // Register handler for socket events. | 1212 // Register handler for socket events. |
1213 _socket.onData = _onData; | 1213 _socket.onData = _onData; |
1214 _socket.onClosed = _onClosed; | 1214 _socket.onClosed = _onClosed; |
1215 _socket.onError = _onError; | 1215 _socket.onError = _onError; |
1216 // Ignore errors in the socket output stream as this is getting | 1216 // Ignore errors in the socket output stream as this is getting |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1300 | 1300 |
1301 abstract void _onConnectionClosed(e); | 1301 abstract void _onConnectionClosed(e); |
1302 abstract void _responseDone(); | 1302 abstract void _responseDone(); |
1303 | 1303 |
1304 void set _onNoPendingWrites(void callback()) { | 1304 void set _onNoPendingWrites(void callback()) { |
1305 if (!_error) { | 1305 if (!_error) { |
1306 _socket.outputStream.onNoPendingWrites = callback; | 1306 _socket.outputStream.onNoPendingWrites = callback; |
1307 } | 1307 } |
1308 } | 1308 } |
1309 | 1309 |
1310 int hashCode() => _hashCode; | |
1311 | |
1312 Socket _socket; | 1310 Socket _socket; |
1313 bool _closing = false; // Is the socket closed by the client? | 1311 bool _closing = false; // Is the socket closed by the client? |
1314 bool _error = false; // Is the socket closed due to an error? | 1312 bool _error = false; // Is the socket closed due to an error? |
1315 _HttpParser _httpParser; | 1313 _HttpParser _httpParser; |
1316 | 1314 |
1317 Queue _sendBuffers; | 1315 Queue _sendBuffers; |
1318 | 1316 |
1319 Function onDetach; | 1317 Function onDetach; |
1320 | 1318 |
1321 // Hash code for HTTP connection. Currently this is just a counter. | 1319 // Hash code for HTTP connection. Currently this is just a counter. |
1322 int _hashCode; | 1320 final int hashCode; |
1323 static int _nextHashCode = 0; | 1321 static int _nextHashCode = 0; |
1324 } | 1322 } |
1325 | 1323 |
1326 | 1324 |
1327 // HTTP server connection over a socket. | 1325 // HTTP server connection over a socket. |
1328 class _HttpConnection extends _HttpConnectionBase { | 1326 class _HttpConnection extends _HttpConnectionBase { |
1329 _HttpConnection(HttpServer this._server) { | 1327 _HttpConnection(HttpServer this._server) { |
1330 // Register HTTP parser callbacks. | 1328 // Register HTTP parser callbacks. |
1331 _httpParser.requestStart = | 1329 _httpParser.requestStart = |
1332 (method, uri, version) => _onRequestStart(method, uri, version); | 1330 (method, uri, version) => _onRequestStart(method, uri, version); |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1957 | 1955 |
1958 void _markReturned() { | 1956 void _markReturned() { |
1959 _socket.onData = null; | 1957 _socket.onData = null; |
1960 _socket.onClosed = null; | 1958 _socket.onClosed = null; |
1961 _socket.onError = null; | 1959 _socket.onError = null; |
1962 _returnTime = new Date.now(); | 1960 _returnTime = new Date.now(); |
1963 } | 1961 } |
1964 | 1962 |
1965 Duration _idleTime(Date now) => now.difference(_returnTime); | 1963 Duration _idleTime(Date now) => now.difference(_returnTime); |
1966 | 1964 |
1967 int hashCode() => _socket.hashCode(); | 1965 int get hashCode => _socket.hashCode; |
1968 | 1966 |
1969 String _host; | 1967 String _host; |
1970 int _port; | 1968 int _port; |
1971 Socket _socket; | 1969 Socket _socket; |
1972 Date _returnTime; | 1970 Date _returnTime; |
1973 } | 1971 } |
1974 | 1972 |
1975 class _ProxyConfiguration { | 1973 class _ProxyConfiguration { |
1976 static const String PROXY_PREFIX = "PROXY "; | 1974 static const String PROXY_PREFIX = "PROXY "; |
1977 static const String DIRECT_PREFIX = "DIRECT"; | 1975 static const String DIRECT_PREFIX = "DIRECT"; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 | 2289 |
2292 | 2290 |
2293 class _RedirectInfo implements RedirectInfo { | 2291 class _RedirectInfo implements RedirectInfo { |
2294 const _RedirectInfo(int this.statusCode, | 2292 const _RedirectInfo(int this.statusCode, |
2295 String this.method, | 2293 String this.method, |
2296 Uri this.location); | 2294 Uri this.location); |
2297 final int statusCode; | 2295 final int statusCode; |
2298 final String method; | 2296 final String method; |
2299 final Uri location; | 2297 final Uri location; |
2300 } | 2298 } |
OLD | NEW |