serveRequests function

void serveRequests (
  1. Stream<HttpRequest> requests,
  2. Handler handler
)

Serve a Stream of HttpRequests.

HttpServer implements Stream<HttpRequest> so it can be passed directly to serveRequests.

Errors thrown by handler while serving a request will be printed to the console and cause a 500 response with no body. Errors thrown asynchronously by handler will be printed to the console or, if there's an active error zone, passed to that zone.

Implementation

void serveRequests(Stream<HttpRequest> requests, Handler handler) {
  catchTopLevelErrors(() {
    requests.listen((request) => handleRequest(request, handler));
  }, (error, stackTrace) {
    _logTopLevelError('Asynchronous error\n$error', stackTrace);
  });
}