From 38c216a61a3dc389d1ddab2a37b4b032a6de13d0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 12 Nov 2016 19:30:03 -0500 Subject: [PATCH] update response streams --- SocketHttpListener.Portable/Net/HttpConnection.cs | 6 +++--- SocketHttpListener.Portable/Net/HttpListenerRequest.cs | 9 ++------- SocketHttpListener.Portable/Net/HttpListenerResponse.cs | 4 ++-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/SocketHttpListener.Portable/Net/HttpConnection.cs b/SocketHttpListener.Portable/Net/HttpConnection.cs index 67dd5c9584..d9fd97ed2f 100644 --- a/SocketHttpListener.Portable/Net/HttpConnection.cs +++ b/SocketHttpListener.Portable/Net/HttpConnection.cs @@ -204,12 +204,12 @@ namespace SocketHttpListener.Net return i_stream; } - public Stream GetResponseStream(HttpListenerRequest request) + public Stream GetResponseStream(bool isExpect100Continue = false) { // TODO: can we get this stream before reading the input? if (o_stream == null) { - if (context.Response.SendChunked || request == null || request.HasExpect100Continue) + if (context.Response.SendChunked || isExpect100Continue) { o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding); } @@ -490,7 +490,7 @@ namespace SocketHttpListener.Net { if (!context.Request.IsWebSocketRequest || force_close) { - Stream st = GetResponseStream(context.Request); + Stream st = GetResponseStream(); if (st != null) st.Dispose(); diff --git a/SocketHttpListener.Portable/Net/HttpListenerRequest.cs b/SocketHttpListener.Portable/Net/HttpListenerRequest.cs index 767f1c5425..811cc6ddb6 100644 --- a/SocketHttpListener.Portable/Net/HttpListenerRequest.cs +++ b/SocketHttpListener.Portable/Net/HttpListenerRequest.cs @@ -179,9 +179,9 @@ namespace SocketHttpListener.Net } } - if (HasExpect100Continue) + if (String.Compare(Headers["Expect"], "100-continue", StringComparison.OrdinalIgnoreCase) == 0) { - var output = (ResponseStream)context.Connection.GetResponseStream(this); + var output = (ResponseStream)context.Connection.GetResponseStream(true); var _100continue = _textEncoding.GetASCIIEncoding().GetBytes("HTTP/1.1 100 Continue\r\n\r\n"); @@ -189,11 +189,6 @@ namespace SocketHttpListener.Net } } - public bool HasExpect100Continue - { - get { return String.Compare(Headers["Expect"], "100-continue", StringComparison.OrdinalIgnoreCase) == 0; } - } - static bool MaybeUri(string s) { int p = s.IndexOf(':'); diff --git a/SocketHttpListener.Portable/Net/HttpListenerResponse.cs b/SocketHttpListener.Portable/Net/HttpListenerResponse.cs index 8c610d725a..93358cae42 100644 --- a/SocketHttpListener.Portable/Net/HttpListenerResponse.cs +++ b/SocketHttpListener.Portable/Net/HttpListenerResponse.cs @@ -149,7 +149,7 @@ namespace SocketHttpListener.Net get { if (output_stream == null) - output_stream = context.Connection.GetResponseStream(context.Request); + output_stream = context.Connection.GetResponseStream(); return output_stream; } } @@ -489,7 +489,7 @@ namespace SocketHttpListener.Net int preamble = encoding.GetPreamble().Length; if (output_stream == null) - output_stream = context.Connection.GetResponseStream(context.Request); + output_stream = context.Connection.GetResponseStream(); /* Assumes that the ms was at position 0 */ ms.Position = preamble;