From b9e592026f6727a84ed3bf82e348efae18ea32e4 Mon Sep 17 00:00:00 2001 From: Luiz Mineo Date: Sun, 12 Oct 2014 16:20:14 -0300 Subject: [PATCH] Fix: handle invalid requests --- lib/src/server_impl.dart | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/src/server_impl.dart b/lib/src/server_impl.dart index a5ab7ec..f05e37c 100644 --- a/lib/src/server_impl.dart +++ b/lib/src/server_impl.dart @@ -159,10 +159,19 @@ void _process(UnparsedRequest req, _RequestState state, _ChainImpl chain, Completer completer) { runZoned(() { - shelf_io.handleRequest(req.httpRequest, _mainHandler).then((_) { - _logger.finer("Closed request for: ${request.url}"); - completer.complete(req.httpRequest.response); - }); + try { + shelf_io.handleRequest(req.httpRequest, _mainHandler).then((_) { + _logger.finer("Closed request for: ${request.url}"); + completer.complete(req.httpRequest.response); + }); + } catch (e) { + //Shelf is throwing synchronous errors for invalid requests + _handleError("Invalid request!", e, logLevel: Level.FINE); + //avoid resource leak + try { + req.httpRequest.response.close(); + } catch(e) {} + } }, zoneValues: { #request: req,