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 import 'dart:uri'; | 9 import 'dart:uri'; |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 int get port => _inner.port; | 36 int get port => _inner.port; |
37 | 37 |
38 set sessionTimeout(int timeout) { | 38 set sessionTimeout(int timeout) { |
39 _inner.sessionTimeout = timeout; | 39 _inner.sessionTimeout = timeout; |
40 } | 40 } |
41 | 41 |
42 HttpConnectionsInfo connectionsInfo() => _inner.connectionsInfo(); | 42 HttpConnectionsInfo connectionsInfo() => _inner.connectionsInfo(); |
43 | 43 |
44 StreamSubscription<HttpRequest> listen(void onData(HttpRequest value), | 44 StreamSubscription<HttpRequest> listen(void onData(HttpRequest value), |
45 {void onError(AsyncError error), void onDone(), | 45 {void onError(error), void onDone(), |
46 bool cancelOnError: false}) { | 46 bool cancelOnError: false}) { |
47 var subscription; | 47 var subscription; |
48 subscription = super.listen((request) { | 48 subscription = super.listen((request) { |
49 onData(new _HttpRequestWrapper(request)); | 49 onData(new _HttpRequestWrapper(request)); |
50 }, onError: (e) { | 50 }, onError: (error) { |
51 var error = e.error; | |
52 // Ignore socket error 104, which is caused by a request being cancelled | 51 // Ignore socket error 104, which is caused by a request being cancelled |
53 // before it writes any headers. There's no reason to care about such | 52 // before it writes any headers. There's no reason to care about such |
54 // requests. | 53 // requests. |
55 if (error is SocketIOException && error.osError.errorCode == 104) return; | 54 if (error is SocketIOException && error.osError.errorCode == 104) return; |
56 // Ignore any parsing errors, which come from malformed requests. | 55 // Ignore any parsing errors, which come from malformed requests. |
57 if (error is HttpParserException) return; | 56 if (error is HttpParserException) return; |
58 // Manually handle cancelOnError so the above (ignored) errors don't | 57 // Manually handle cancelOnError so the above (ignored) errors don't |
59 // cause unsubscription. | 58 // cause unsubscription. |
60 if (cancelOnError) subscription.cancel(); | 59 if (cancelOnError) subscription.cancel(); |
61 if (onError != null) onError(e); | 60 if (onError != null) onError(error); |
62 }, onDone: onDone); | 61 }, onDone: onDone); |
63 return subscription; | 62 return subscription; |
64 } | 63 } |
65 } | 64 } |
66 | 65 |
67 /// A wrapper around [HttpRequest] for the sole purpose of swallowing errors on | 66 /// A wrapper around [HttpRequest] for the sole purpose of swallowing errors on |
68 /// [HttpResponse.done]. | 67 /// [HttpResponse.done]. |
69 class _HttpRequestWrapper extends StreamView<List<int>> implements HttpRequest { | 68 class _HttpRequestWrapper extends StreamView<List<int>> implements HttpRequest { |
70 final HttpRequest _inner; | 69 final HttpRequest _inner; |
71 final HttpResponse response; | 70 final HttpResponse response; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 void add(List<int> data) => _inner.add(data); | 133 void add(List<int> data) => _inner.add(data); |
135 Future<HttpResponse> addStream(Stream<List<int>> stream) => | 134 Future<HttpResponse> addStream(Stream<List<int>> stream) => |
136 _inner.addStream(stream); | 135 _inner.addStream(stream); |
137 Future close() => _inner.close(); | 136 Future close() => _inner.close(); |
138 void write(Object obj) => _inner.write(obj); | 137 void write(Object obj) => _inner.write(obj); |
139 void writeAll(Iterable objects, [String separator = ""]) => | 138 void writeAll(Iterable objects, [String separator = ""]) => |
140 _inner.writeAll(objects, separator); | 139 _inner.writeAll(objects, separator); |
141 void writeCharCode(int charCode) => _inner.writeCharCode(charCode); | 140 void writeCharCode(int charCode) => _inner.writeCharCode(charCode); |
142 void writeln([Object obj = ""]) => _inner.writeln(obj); | 141 void writeln([Object obj = ""]) => _inner.writeln(obj); |
143 } | 142 } |
OLD | NEW |