| 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 |
| 11 // TODO(nweiz): remove this when issue 9140 is fixed. | 11 // TODO(nweiz): remove this when issue 9140 is fixed. |
| 12 /// A wrapper around [HttpServer] that swallows errors caused by requests | 12 /// A wrapper around [HttpServer] that swallows errors caused by requests |
| 13 /// behaving badly. This provides the following guarantees: | 13 /// behaving badly. This provides the following guarantees: |
| 14 /// | 14 /// |
| 15 /// * The [SafeHttpServer.listen] onError callback will only emit server-wide | 15 /// * The [SafeHttpServer.listen] onError callback will only emit server-wide |
| 16 /// errors. It will not emit errors for requests that were unparseable or | 16 /// errors. It will not emit errors for requests that were unparseable or |
| 17 /// where the connection was closed too soon. | 17 /// where the connection was closed too soon. |
| 18 /// * [HttpResponse.done] will emit no errors. | 18 /// * [HttpResponse.done] will emit no errors. |
| 19 /// | 19 /// |
| 20 /// The [HttpRequest] data stream can still emit errors. | 20 /// The [HttpRequest] data stream can still emit errors. |
| 21 class SafeHttpServer extends StreamView<HttpRequest> implements HttpServer { | 21 class SafeHttpServer extends StreamView<HttpRequest> implements HttpServer { |
| 22 final HttpServer _inner; | 22 final HttpServer _inner; |
| 23 | 23 |
| 24 static Future<SafeHttpServer> bind([String host = "127.0.0.1", | 24 static Future<SafeHttpServer> bind([String host = "127.0.0.1", |
| 25 int port = 0, int backlog = 0]) { | 25 int port = 0, int backlog = 0]) { |
| 26 return HttpServer.bind(host, port, backlog) | 26 return HttpServer.bind(host, port, backlog: backlog) |
| 27 .then((server) => new SafeHttpServer(server)); | 27 .then((server) => new SafeHttpServer(server)); |
| 28 } | 28 } |
| 29 | 29 |
| 30 SafeHttpServer(HttpServer server) | 30 SafeHttpServer(HttpServer server) |
| 31 : super(server), | 31 : super(server), |
| 32 _inner = server; | 32 _inner = server; |
| 33 | 33 |
| 34 void close() => _inner.close(); | 34 void close() => _inner.close(); |
| 35 | 35 |
| 36 int get port => _inner.port; | 36 int get port => _inner.port; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 Future<HttpResponse> addStream(Stream<List<int>> stream) => | 134 Future<HttpResponse> addStream(Stream<List<int>> stream) => |
| 135 _inner.addStream(stream); | 135 _inner.addStream(stream); |
| 136 Future close() => _inner.close(); | 136 Future close() => _inner.close(); |
| 137 void write(Object obj) => _inner.write(obj); | 137 void write(Object obj) => _inner.write(obj); |
| 138 void writeAll(Iterable objects, [String separator = ""]) => | 138 void writeAll(Iterable objects, [String separator = ""]) => |
| 139 _inner.writeAll(objects, separator); | 139 _inner.writeAll(objects, separator); |
| 140 void writeCharCode(int charCode) => _inner.writeCharCode(charCode); | 140 void writeCharCode(int charCode) => _inner.writeCharCode(charCode); |
| 141 void writeln([Object obj = ""]) => _inner.writeln(obj); | 141 void writeln([Object obj = ""]) => _inner.writeln(obj); |
| 142 void addError(error) => _inner.addError(error); | 142 void addError(error) => _inner.addError(error); |
| 143 } | 143 } |
| OLD | NEW |