Chromium Code Reviews| 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 library safe_http_server; | 5 library safe_http_server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 // TODO(nweiz): remove this when issue 9140 is fixed. | 10 // TODO(nweiz): remove this when issue 9140 is fixed. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 | 34 |
| 35 int get port => _inner.port; | 35 int get port => _inner.port; |
| 36 | 36 |
| 37 set sessionTimeout(int timeout) { | 37 set sessionTimeout(int timeout) { |
| 38 _inner.sessionTimeout = timeout; | 38 _inner.sessionTimeout = timeout; |
| 39 } | 39 } |
| 40 | 40 |
| 41 HttpConnectionsInfo connectionsInfo() => _inner.connectionsInfo(); | 41 HttpConnectionsInfo connectionsInfo() => _inner.connectionsInfo(); |
| 42 | 42 |
| 43 StreamSubscription<HttpRequest> listen(void onData(HttpRequest value), | 43 StreamSubscription<HttpRequest> listen(void onData(HttpRequest value), |
| 44 {void onError(error), void onDone(), | 44 {Function onError, void onDone(), |
| 45 bool cancelOnError: false}) { | 45 bool cancelOnError: false}) { |
| 46 var subscription; | 46 var subscription; |
| 47 subscription = super.listen((request) { | 47 subscription = super.listen((request) { |
| 48 onData(new _HttpRequestWrapper(request)); | 48 onData(new _HttpRequestWrapper(request)); |
| 49 }, onError: (error) { | 49 }, onError: (error, [StackTrace stackTrace]) { |
|
Lasse Reichstein Nielsen
2013/10/04 08:45:17
make not optional.
floitsch
2013/10/05 18:11:48
Done.
| |
| 50 // Ignore socket error 104, which is caused by a request being cancelled | 50 // Ignore socket error 104, which is caused by a request being cancelled |
| 51 // before it writes any headers. There's no reason to care about such | 51 // before it writes any headers. There's no reason to care about such |
| 52 // requests. | 52 // requests. |
| 53 if (error is SocketException && error.osError.errorCode == 104) return; | 53 if (error is SocketException && error.osError.errorCode == 104) return; |
| 54 // Ignore any parsing errors, which come from malformed requests. | 54 // Ignore any parsing errors, which come from malformed requests. |
| 55 if (error is HttpException) return; | 55 if (error is HttpException) return; |
| 56 // Manually handle cancelOnError so the above (ignored) errors don't | 56 // Manually handle cancelOnError so the above (ignored) errors don't |
| 57 // cause unsubscription. | 57 // cause unsubscription. |
| 58 if (cancelOnError) subscription.cancel(); | 58 if (cancelOnError) subscription.cancel(); |
| 59 if (onError != null) onError(error); | 59 if (onError != null) { |
| 60 if (onError is ZoneBinaryCallback) { | |
| 61 onError(error, stackTrace); | |
| 62 } else { | |
| 63 onError(error); | |
| 64 } | |
| 65 } | |
| 60 }, onDone: onDone); | 66 }, onDone: onDone); |
| 61 return subscription; | 67 return subscription; |
| 62 } | 68 } |
| 63 } | 69 } |
| 64 | 70 |
| 65 /// A wrapper around [HttpRequest] for the sole purpose of swallowing errors on | 71 /// A wrapper around [HttpRequest] for the sole purpose of swallowing errors on |
| 66 /// [HttpResponse.done]. | 72 /// [HttpResponse.done]. |
| 67 class _HttpRequestWrapper extends StreamView<List<int>> implements HttpRequest { | 73 class _HttpRequestWrapper extends StreamView<List<int>> implements HttpRequest { |
| 68 final HttpRequest _inner; | 74 final HttpRequest _inner; |
| 69 final HttpResponse response; | 75 final HttpResponse response; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 Future<HttpResponse> addStream(Stream<List<int>> stream) => | 138 Future<HttpResponse> addStream(Stream<List<int>> stream) => |
| 133 _inner.addStream(stream); | 139 _inner.addStream(stream); |
| 134 Future close() => _inner.close(); | 140 Future close() => _inner.close(); |
| 135 void write(Object obj) => _inner.write(obj); | 141 void write(Object obj) => _inner.write(obj); |
| 136 void writeAll(Iterable objects, [String separator = ""]) => | 142 void writeAll(Iterable objects, [String separator = ""]) => |
| 137 _inner.writeAll(objects, separator); | 143 _inner.writeAll(objects, separator); |
| 138 void writeCharCode(int charCode) => _inner.writeCharCode(charCode); | 144 void writeCharCode(int charCode) => _inner.writeCharCode(charCode); |
| 139 void writeln([Object obj = ""]) => _inner.writeln(obj); | 145 void writeln([Object obj = ""]) => _inner.writeln(obj); |
| 140 void addError(error) => _inner.addError(error); | 146 void addError(error) => _inner.addError(error); |
| 141 } | 147 } |
| OLD | NEW |