update response streams

This commit is contained in:
Luke Pulverenti 2016-11-12 19:30:03 -05:00
parent 102bbe2beb
commit 38c216a61a
3 changed files with 7 additions and 12 deletions

View file

@ -204,12 +204,12 @@ namespace SocketHttpListener.Net
return i_stream; return i_stream;
} }
public Stream GetResponseStream(HttpListenerRequest request) public Stream GetResponseStream(bool isExpect100Continue = false)
{ {
// TODO: can we get this stream before reading the input? // TODO: can we get this stream before reading the input?
if (o_stream == null) 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); o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding);
} }
@ -490,7 +490,7 @@ namespace SocketHttpListener.Net
{ {
if (!context.Request.IsWebSocketRequest || force_close) if (!context.Request.IsWebSocketRequest || force_close)
{ {
Stream st = GetResponseStream(context.Request); Stream st = GetResponseStream();
if (st != null) if (st != null)
st.Dispose(); st.Dispose();

View file

@ -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"); 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) static bool MaybeUri(string s)
{ {
int p = s.IndexOf(':'); int p = s.IndexOf(':');

View file

@ -149,7 +149,7 @@ namespace SocketHttpListener.Net
get get
{ {
if (output_stream == null) if (output_stream == null)
output_stream = context.Connection.GetResponseStream(context.Request); output_stream = context.Connection.GetResponseStream();
return output_stream; return output_stream;
} }
} }
@ -489,7 +489,7 @@ namespace SocketHttpListener.Net
int preamble = encoding.GetPreamble().Length; int preamble = encoding.GetPreamble().Length;
if (output_stream == null) if (output_stream == null)
output_stream = context.Connection.GetResponseStream(context.Request); output_stream = context.Connection.GetResponseStream();
/* Assumes that the ms was at position 0 */ /* Assumes that the ms was at position 0 */
ms.Position = preamble; ms.Position = preamble;