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 pub.safe_http_server; | 5 library pub.safe_http_server; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 } | 45 } |
46 | 46 |
47 Duration get idleTimeout => _inner.idleTimeout; | 47 Duration get idleTimeout => _inner.idleTimeout; |
48 set idleTimeout(Duration value) { | 48 set idleTimeout(Duration value) { |
49 _inner.idleTimeout = value; | 49 _inner.idleTimeout = value; |
50 } | 50 } |
51 | 51 |
52 HttpConnectionsInfo connectionsInfo() => _inner.connectionsInfo(); | 52 HttpConnectionsInfo connectionsInfo() => _inner.connectionsInfo(); |
53 | 53 |
54 StreamSubscription<HttpRequest> listen(void onData(HttpRequest value), | 54 StreamSubscription<HttpRequest> listen(void onData(HttpRequest value), |
55 {void onError(error), void onDone(), | 55 {Function onError, void onDone(), |
56 bool cancelOnError: false}) { | 56 bool cancelOnError: false}) { |
57 var subscription; | 57 var subscription; |
58 subscription = super.listen((request) { | 58 subscription = super.listen((request) { |
59 onData(new _HttpRequestWrapper(request)); | 59 onData(new _HttpRequestWrapper(request)); |
60 }, onError: (error) { | 60 }, onError: (error, [stackTrace]) { |
61 // Ignore socket error 104, which is caused by a request being cancelled | 61 // Ignore socket error 104, which is caused by a request being cancelled |
62 // before it writes any headers. There's no reason to care about such | 62 // before it writes any headers. There's no reason to care about such |
63 // requests. | 63 // requests. |
64 if (error is SocketException && error.osError.errorCode == 104) return; | 64 if (error is SocketException && error.osError.errorCode == 104) return; |
65 // Ignore any parsing errors, which come from malformed requests. | 65 // Ignore any parsing errors, which come from malformed requests. |
66 if (error is HttpException) return; | 66 if (error is HttpException) return; |
67 // Manually handle cancelOnError so the above (ignored) errors don't | 67 // Manually handle cancelOnError so the above (ignored) errors don't |
68 // cause unsubscription. | 68 // cause unsubscription. |
69 if (cancelOnError) subscription.cancel(); | 69 if (cancelOnError) subscription.cancel(); |
70 if (onError != null) onError(error); | 70 if (onError != null) { |
| 71 if (onError is ZoneBinaryCallback) { |
| 72 onError(error, stackTrace); |
| 73 } else { |
| 74 onError(error); |
| 75 } |
| 76 } |
71 }, onDone: onDone); | 77 }, onDone: onDone); |
72 return subscription; | 78 return subscription; |
73 } | 79 } |
74 } | 80 } |
75 | 81 |
76 /// A wrapper around [HttpRequest] for the sole purpose of swallowing errors on | 82 /// A wrapper around [HttpRequest] for the sole purpose of swallowing errors on |
77 /// [HttpResponse.done]. | 83 /// [HttpResponse.done]. |
78 class _HttpRequestWrapper extends StreamView<List<int>> implements HttpRequest { | 84 class _HttpRequestWrapper extends StreamView<List<int>> implements HttpRequest { |
79 final HttpRequest _inner; | 85 final HttpRequest _inner; |
80 final HttpResponse response; | 86 final HttpResponse response; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void addError(error) => _inner.addError(error); | 157 void addError(error) => _inner.addError(error); |
152 | 158 |
153 Duration get deadline => _inner.deadline; | 159 Duration get deadline => _inner.deadline; |
154 set deadline(Duration value) { | 160 set deadline(Duration value) { |
155 _inner.deadline = value; | 161 _inner.deadline = value; |
156 } | 162 } |
157 | 163 |
158 Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY}) => | 164 Future redirect(Uri location, {int status: HttpStatus.MOVED_TEMPORARILY}) => |
159 _inner.redirect(location, status: status); | 165 _inner.redirect(location, status: status); |
160 } | 166 } |
OLD | NEW |