From edde0e8dd8c1ff716c389922f0729305e069769b Mon Sep 17 00:00:00 2001 From: Nick Abalov Date: Fri, 16 Sep 2016 16:40:57 +0700 Subject: [PATCH] Fix listener crashing on empty incoming request --- Winium/Winium.StoreApps.Driver/Listener.cs | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Winium/Winium.StoreApps.Driver/Listener.cs b/Winium/Winium.StoreApps.Driver/Listener.cs index c205e48..f885415 100644 --- a/Winium/Winium.StoreApps.Driver/Listener.cs +++ b/Winium/Winium.StoreApps.Driver/Listener.cs @@ -91,19 +91,27 @@ public void StartListening() using (var stream = client.GetStream()) { var acceptedRequest = HttpRequest.ReadFromStreamWithoutClosing(stream); - Logger.Debug("ACCEPTED REQUEST {0}", acceptedRequest.StartingLine); - var response = this.HandleRequest(acceptedRequest); - using (var writer = new StreamWriter(stream)) + if (string.IsNullOrWhiteSpace(acceptedRequest.StartingLine)) { - try - { - writer.Write(response); - writer.Flush(); - } - catch (IOException ex) + Logger.Warn("ACCEPTED EMPTY REQUEST"); + } + else + { + Logger.Debug("ACCEPTED REQUEST {0}", acceptedRequest.StartingLine); + + var response = this.HandleRequest(acceptedRequest); + using (var writer = new StreamWriter(stream)) { - Logger.Error("Error occured while writing response: {0}", ex); + try + { + writer.Write(response); + writer.Flush(); + } + catch (IOException ex) + { + Logger.Error("Error occured while writing response: {0}", ex); + } } }