Skip to content

Commit

Permalink
Fix listener crashing on empty incoming request
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Abalov authored and Nick Abalov committed Sep 16, 2016
1 parent b13e135 commit edde0e8
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions Winium/Winium.StoreApps.Driver/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit edde0e8

Please sign in to comment.