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 _HEADERS_BUFFER_SIZE = 8 * 1024; | 7 const int _HEADERS_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 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 bool closed = false; | 1239 bool closed = false; |
1240 Uri _currentUri; | 1240 Uri _currentUri; |
1241 final Uint8List _headersBuffer = new Uint8List(_HEADERS_BUFFER_SIZE); | 1241 final Uint8List _headersBuffer = new Uint8List(_HEADERS_BUFFER_SIZE); |
1242 | 1242 |
1243 Completer<_HttpIncoming> _nextResponseCompleter; | 1243 Completer<_HttpIncoming> _nextResponseCompleter; |
1244 Future _streamFuture; | 1244 Future _streamFuture; |
1245 | 1245 |
1246 _HttpClientConnection(this.key, this._socket, this._httpClient, | 1246 _HttpClientConnection(this.key, this._socket, this._httpClient, |
1247 [this._proxyTunnel = false]) | 1247 [this._proxyTunnel = false]) |
1248 : _httpParser = new _HttpParser.responseParser() { | 1248 : _httpParser = new _HttpParser.responseParser() { |
1249 _socket.pipe(_httpParser); | 1249 _httpParser.listenToStream(_socket); |
1250 | 1250 |
1251 // Set up handlers on the parser here, so we are sure to get 'onDone' from | 1251 // Set up handlers on the parser here, so we are sure to get 'onDone' from |
1252 // the parser. | 1252 // the parser. |
1253 _subscription = _httpParser.listen( | 1253 _subscription = _httpParser.listen( |
1254 (incoming) { | 1254 (incoming) { |
1255 // Only handle one incoming response at the time. Keep the | 1255 // Only handle one incoming response at the time. Keep the |
1256 // stream paused until the response have been processed. | 1256 // stream paused until the response have been processed. |
1257 _subscription.pause(); | 1257 _subscription.pause(); |
1258 // We assume the response is not here, until we have send the request. | 1258 // We assume the response is not here, until we have send the request. |
1259 if (_nextResponseCompleter == null) { | 1259 if (_nextResponseCompleter == null) { |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1901 final _HttpParser _httpParser; | 1901 final _HttpParser _httpParser; |
1902 StreamSubscription _subscription; | 1902 StreamSubscription _subscription; |
1903 Timer _idleTimer; | 1903 Timer _idleTimer; |
1904 final Uint8List _headersBuffer = new Uint8List(_HEADERS_BUFFER_SIZE); | 1904 final Uint8List _headersBuffer = new Uint8List(_HEADERS_BUFFER_SIZE); |
1905 | 1905 |
1906 Future _streamFuture; | 1906 Future _streamFuture; |
1907 | 1907 |
1908 _HttpConnection(this._socket, this._httpServer) | 1908 _HttpConnection(this._socket, this._httpServer) |
1909 : _httpParser = new _HttpParser.requestParser() { | 1909 : _httpParser = new _HttpParser.requestParser() { |
1910 _startTimeout(); | 1910 _startTimeout(); |
1911 _socket.pipe(_httpParser); | 1911 _httpParser.listenToStream(_socket); |
1912 _subscription = _httpParser.listen( | 1912 _subscription = _httpParser.listen( |
1913 (incoming) { | 1913 (incoming) { |
1914 _stopTimeout(); | 1914 _stopTimeout(); |
1915 // If the incoming was closed, close the connection. | 1915 // If the incoming was closed, close the connection. |
1916 incoming.dataDone.then((closing) { | 1916 incoming.dataDone.then((closing) { |
1917 if (closing) destroy(); | 1917 if (closing) destroy(); |
1918 }); | 1918 }); |
1919 // Only handle one incoming request at the time. Keep the | 1919 // Only handle one incoming request at the time. Keep the |
1920 // stream paused until the request has been send. | 1920 // stream paused until the request has been send. |
1921 _subscription.pause(); | 1921 _subscription.pause(); |
(...skipping 16 matching lines...) Expand all Loading... |
1938 _state = _IDLE; | 1938 _state = _IDLE; |
1939 _startTimeout(); | 1939 _startTimeout(); |
1940 // Resume the subscription for incoming requests as the | 1940 // Resume the subscription for incoming requests as the |
1941 // request is now processed. | 1941 // request is now processed. |
1942 _subscription.resume(); | 1942 _subscription.resume(); |
1943 } else { | 1943 } else { |
1944 // Close socket, keep-alive not used or body sent before | 1944 // Close socket, keep-alive not used or body sent before |
1945 // received data was handled. | 1945 // received data was handled. |
1946 destroy(); | 1946 destroy(); |
1947 } | 1947 } |
1948 }) | 1948 }, onError: (_) { |
1949 .catchError((e) { | |
1950 destroy(); | 1949 destroy(); |
1951 }); | 1950 }); |
1952 response._ignoreBody = request.method == "HEAD"; | 1951 response._ignoreBody = request.method == "HEAD"; |
1953 response._httpRequest = request; | 1952 response._httpRequest = request; |
1954 _httpServer._handleRequest(request); | 1953 _httpServer._handleRequest(request); |
1955 }, | 1954 }, |
1956 onDone: () { | 1955 onDone: () { |
1957 destroy(); | 1956 destroy(); |
1958 }, | 1957 }, |
1959 onError: (error) { | 1958 onError: (error) { |
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2568 const _RedirectInfo(this.statusCode, this.method, this.location); | 2567 const _RedirectInfo(this.statusCode, this.method, this.location); |
2569 } | 2568 } |
2570 | 2569 |
2571 String _getHttpVersion() { | 2570 String _getHttpVersion() { |
2572 var version = Platform.version; | 2571 var version = Platform.version; |
2573 // Only include major and minor version numbers. | 2572 // Only include major and minor version numbers. |
2574 int index = version.indexOf('.', version.indexOf('.') + 1); | 2573 int index = version.indexOf('.', version.indexOf('.') + 1); |
2575 version = version.substring(0, index); | 2574 version = version.substring(0, index); |
2576 return 'Dart/$version (dart:io)'; | 2575 return 'Dart/$version (dart:io)'; |
2577 } | 2576 } |
OLD | NEW |