OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 /// A Shelf adapter for handling [HttpRequest] objects from `dart:io`. | 5 /// A Shelf adapter for handling [HttpRequest] objects from `dart:io`. |
6 /// | 6 /// |
7 /// One can provide an instance of [HttpServer] as the `requests` parameter in | 7 /// One can provide an instance of [HttpServer] as the `requests` parameter in |
8 /// [serveRequests]. | 8 /// [serveRequests]. |
9 /// | 9 /// |
10 /// This adapter supports request hijacking; see [Request.hijack]. It also | 10 /// This adapter supports request hijacking; see [Request.hijack]. It also |
11 /// supports the `"shelf.io.buffer_output"` `Response.context` property. If this | 11 /// supports the `"shelf.io.buffer_output"` `Response.context` property. If this |
12 /// property is `true` (the default), streamed responses will be buffered to | 12 /// property is `true` (the default), streamed responses will be buffered to |
13 /// improve performance; if it's `false`, all chunks will be pushed over the | 13 /// improve performance; if it's `false`, all chunks will be pushed over the |
14 /// wire as they're received. See [`HttpResponse.bufferOutput`][bufferOutput] | 14 /// wire as they're received. See [`HttpResponse.bufferOutput`][bufferOutput] |
15 /// for more information. | 15 /// for more information. |
16 /// | 16 /// |
17 /// [bufferOutput]: https://api.dartlang.org/apidocs/channels/stable/dartdoc-vie
wer/dart:io.HttpResponse#id_bufferOutput | 17 /// [bufferOutput]: https://api.dartlang.org/apidocs/channels/stable/dartdoc-vie
wer/dart:io.HttpResponse#id_bufferOutput |
18 library shelf.io; | 18 library shelf.io; |
19 | 19 |
20 import 'dart:async'; | 20 import 'dart:async'; |
21 import 'dart:io'; | 21 import 'dart:io'; |
22 | 22 |
23 import 'package:stack_trace/stack_trace.dart'; | 23 import 'package:stack_trace/stack_trace.dart'; |
24 | 24 |
25 import 'shelf.dart'; | 25 import 'shelf.dart'; |
26 import 'src/util.dart'; | 26 import 'src/util.dart'; |
27 | 27 |
| 28 export 'src/io_server.dart'; |
| 29 |
28 /// Starts an [HttpServer] that listens on the specified [address] and | 30 /// Starts an [HttpServer] that listens on the specified [address] and |
29 /// [port] and sends requests to [handler]. | 31 /// [port] and sends requests to [handler]. |
30 /// | 32 /// |
31 /// See the documentation for [HttpServer.bind] for more details on [address], | 33 /// See the documentation for [HttpServer.bind] for more details on [address], |
32 /// [port], and [backlog]. | 34 /// [port], and [backlog]. |
33 Future<HttpServer> serve(Handler handler, address, int port, {int backlog}) { | 35 Future<HttpServer> serve(Handler handler, address, int port, {int backlog}) { |
34 if (backlog == null) backlog = 0; | 36 if (backlog == null) backlog = 0; |
35 return HttpServer.bind(address, port, backlog: backlog).then((server) { | 37 return HttpServer.bind(address, port, backlog: backlog).then((server) { |
36 serveRequests(server, handler); | 38 serveRequests(server, handler); |
37 return server; | 39 return server; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 chain = new Chain.forTrace(stackTrace); | 160 chain = new Chain.forTrace(stackTrace); |
159 } | 161 } |
160 chain = chain | 162 chain = chain |
161 .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse; | 163 .foldFrames((frame) => frame.isCore || frame.package == 'shelf').terse; |
162 | 164 |
163 stderr.writeln('ERROR - ${new DateTime.now()}'); | 165 stderr.writeln('ERROR - ${new DateTime.now()}'); |
164 stderr.writeln(message); | 166 stderr.writeln(message); |
165 stderr.writeln(chain); | 167 stderr.writeln(chain); |
166 return new Response.internalServerError(); | 168 return new Response.internalServerError(); |
167 } | 169 } |
OLD | NEW |