diff options
Diffstat (limited to 'SocketHttpListener.Portable')
| -rw-r--r-- | SocketHttpListener.Portable/Net/HttpConnection.cs | 4 | ||||
| -rw-r--r-- | SocketHttpListener.Portable/Net/HttpListenerResponse.cs | 16 | ||||
| -rw-r--r-- | SocketHttpListener.Portable/Net/ResponseStream.cs | 2 |
3 files changed, 20 insertions, 2 deletions
diff --git a/SocketHttpListener.Portable/Net/HttpConnection.cs b/SocketHttpListener.Portable/Net/HttpConnection.cs index b09d02254..4b54fc013 100644 --- a/SocketHttpListener.Portable/Net/HttpConnection.cs +++ b/SocketHttpListener.Portable/Net/HttpConnection.cs @@ -209,7 +209,9 @@ namespace SocketHttpListener.Net // TODO: can we get this stream before reading the input? if (o_stream == null) { - if (context.Response.SendChunked || isExpect100Continue || context.Response.ContentLength64 <= 0) + context.Response.DetermineIfChunked(); + + if (context.Response.SendChunked || isExpect100Continue || context.Request.IsWebSocketRequest) { o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding); } diff --git a/SocketHttpListener.Portable/Net/HttpListenerResponse.cs b/SocketHttpListener.Portable/Net/HttpListenerResponse.cs index 880473c0a..c1182de34 100644 --- a/SocketHttpListener.Portable/Net/HttpListenerResponse.cs +++ b/SocketHttpListener.Portable/Net/HttpListenerResponse.cs @@ -362,6 +362,22 @@ namespace SocketHttpListener.Net return false; } + public void DetermineIfChunked() + { + if (chunked) + { + return ; + } + + Version v = context.Request.ProtocolVersion; + if (!cl_set && !chunked && v >= HttpVersion.Version11) + chunked = true; + if (!chunked && string.Equals(headers["Transfer-Encoding"], "chunked")) + { + chunked = true; + } + } + internal void SendHeaders(bool closing, MemoryStream ms) { Encoding encoding = content_encoding; diff --git a/SocketHttpListener.Portable/Net/ResponseStream.cs b/SocketHttpListener.Portable/Net/ResponseStream.cs index 7a6425dea..6067a89ec 100644 --- a/SocketHttpListener.Portable/Net/ResponseStream.cs +++ b/SocketHttpListener.Portable/Net/ResponseStream.cs @@ -14,7 +14,7 @@ namespace SocketHttpListener.Net // Update: we send a single packet for the first non-chunked Write // What happens when we set content-length to X and write X-1 bytes then close? // what if we don't set content-length at all? - class ResponseStream : Stream + public class ResponseStream : Stream { HttpListenerResponse response; bool disposed; |
