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 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 var future = writeHeaders(); | 1048 var future = writeHeaders(); |
1049 if (future != null) { | 1049 if (future != null) { |
1050 // While incoming is being drained, the pauseFuture is non-null. Pause | 1050 // While incoming is being drained, the pauseFuture is non-null. Pause |
1051 // output until it's drained. | 1051 // output until it's drained. |
1052 sub.pause(future); | 1052 sub.pause(future); |
1053 } | 1053 } |
1054 } | 1054 } |
1055 return socket.addStream(controller.stream) | 1055 return socket.addStream(controller.stream) |
1056 .then((_) { | 1056 .then((_) { |
1057 return outbound; | 1057 return outbound; |
1058 }, onError: (error) { | 1058 }, onError: (error, stackTrace) { |
1059 // Be sure to close it in case of an error. | 1059 // Be sure to close it in case of an error. |
1060 if (_gzip) _gzipSink.close(); | 1060 if (_gzip) _gzipSink.close(); |
1061 _socketError = true; | 1061 _socketError = true; |
1062 _doneCompleter.completeError(error); | 1062 _doneCompleter.completeError(error, stackTrace); |
1063 if (_ignoreError(error)) { | 1063 if (_ignoreError(error)) { |
1064 return outbound; | 1064 return outbound; |
1065 } else { | 1065 } else { |
1066 throw error; | 1066 throw error; |
1067 } | 1067 } |
1068 }); | 1068 }); |
1069 } | 1069 } |
1070 | 1070 |
1071 Future close() { | 1071 Future close() { |
1072 // If we are already closed, return that future. | 1072 // If we are already closed, return that future. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 } | 1126 } |
1127 // Clear references, for better GC. | 1127 // Clear references, for better GC. |
1128 _buffer = null; | 1128 _buffer = null; |
1129 // And finally flush it. As we support keep-alive, never close it from | 1129 // And finally flush it. As we support keep-alive, never close it from |
1130 // here. Once the socket is flushed, we'll be able to reuse it (signaled | 1130 // here. Once the socket is flushed, we'll be able to reuse it (signaled |
1131 // by the 'done' future). | 1131 // by the 'done' future). |
1132 return socket.flush() | 1132 return socket.flush() |
1133 .then((_) { | 1133 .then((_) { |
1134 _doneCompleter.complete(socket); | 1134 _doneCompleter.complete(socket); |
1135 return outbound; | 1135 return outbound; |
1136 }, onError: (error) { | 1136 }, onError: (error, stackTrace) { |
1137 _doneCompleter.completeError(error); | 1137 _doneCompleter.completeError(error, stackTrace); |
1138 if (_ignoreError(error)) { | 1138 if (_ignoreError(error)) { |
1139 return outbound; | 1139 return outbound; |
1140 } else { | 1140 } else { |
1141 throw error; | 1141 throw error; |
1142 } | 1142 } |
1143 }); | 1143 }); |
1144 } | 1144 } |
1145 | 1145 |
1146 var future = writeHeaders(); | 1146 var future = writeHeaders(); |
1147 if (future != null) { | 1147 if (future != null) { |
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2239 {Function onError, | 2239 {Function onError, |
2240 void onDone(), | 2240 void onDone(), |
2241 bool cancelOnError}) { | 2241 bool cancelOnError}) { |
2242 _serverSocket.listen( | 2242 _serverSocket.listen( |
2243 (Socket socket) { | 2243 (Socket socket) { |
2244 socket.setOption(SocketOption.TCP_NODELAY, true); | 2244 socket.setOption(SocketOption.TCP_NODELAY, true); |
2245 // Accept the client connection. | 2245 // Accept the client connection. |
2246 _HttpConnection connection = new _HttpConnection(socket, this); | 2246 _HttpConnection connection = new _HttpConnection(socket, this); |
2247 _idleConnections.add(connection); | 2247 _idleConnections.add(connection); |
2248 }, | 2248 }, |
2249 onError: (error) { | 2249 onError: (error, stackTrace) { |
2250 // Ignore HandshakeExceptions as they are bound to a single request, | 2250 // Ignore HandshakeExceptions as they are bound to a single request, |
2251 // and are not fatal for the server. | 2251 // and are not fatal for the server. |
2252 if (error is! HandshakeException) { | 2252 if (error is! HandshakeException) { |
2253 _controller.addError(error); | 2253 _controller.addError(error, stackTrace); |
2254 } | 2254 } |
2255 }, | 2255 }, |
2256 onDone: _controller.close); | 2256 onDone: _controller.close); |
2257 return _controller.stream.listen(onData, | 2257 return _controller.stream.listen(onData, |
2258 onError: onError, | 2258 onError: onError, |
2259 onDone: onDone, | 2259 onDone: onDone, |
2260 cancelOnError: cancelOnError); | 2260 cancelOnError: cancelOnError); |
2261 } | 2261 } |
2262 | 2262 |
2263 Future close({bool force: false}) { | 2263 Future close({bool force: false}) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2308 } | 2308 } |
2309 | 2309 |
2310 void _handleRequest(_HttpRequest request) { | 2310 void _handleRequest(_HttpRequest request) { |
2311 if (!closed) { | 2311 if (!closed) { |
2312 _controller.add(request); | 2312 _controller.add(request); |
2313 } else { | 2313 } else { |
2314 request._httpConnection.destroy(); | 2314 request._httpConnection.destroy(); |
2315 } | 2315 } |
2316 } | 2316 } |
2317 | 2317 |
2318 void _handleError(error) { | |
2319 if (!closed) _controller.addError(error); | |
2320 } | |
2321 | |
2322 void _connectionClosed(_HttpConnection connection) { | 2318 void _connectionClosed(_HttpConnection connection) { |
2323 // Remove itself from either idle or active connections. | 2319 // Remove itself from either idle or active connections. |
2324 connection.unlink(); | 2320 connection.unlink(); |
2325 _maybePerformCleanup(); | 2321 _maybePerformCleanup(); |
2326 } | 2322 } |
2327 | 2323 |
2328 void _markIdle(_HttpConnection connection) { | 2324 void _markIdle(_HttpConnection connection) { |
2329 _activeConnections.remove(connection); | 2325 _activeConnections.remove(connection); |
2330 _idleConnections.add(connection); | 2326 _idleConnections.add(connection); |
2331 } | 2327 } |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2816 const _RedirectInfo(this.statusCode, this.method, this.location); | 2812 const _RedirectInfo(this.statusCode, this.method, this.location); |
2817 } | 2813 } |
2818 | 2814 |
2819 String _getHttpVersion() { | 2815 String _getHttpVersion() { |
2820 var version = Platform.version; | 2816 var version = Platform.version; |
2821 // Only include major and minor version numbers. | 2817 // Only include major and minor version numbers. |
2822 int index = version.indexOf('.', version.indexOf('.') + 1); | 2818 int index = version.indexOf('.', version.indexOf('.') + 1); |
2823 version = version.substring(0, index); | 2819 version = version.substring(0, index); |
2824 return 'Dart/$version (dart:io)'; | 2820 return 'Dart/$version (dart:io)'; |
2825 } | 2821 } |
OLD | NEW |