update response stream handling

This commit is contained in:
Luke Pulverenti 2016-11-12 03:02:46 -05:00
parent 6865bb5353
commit 1714cb8764
7 changed files with 32 additions and 15 deletions

View File

@ -1136,9 +1136,6 @@ namespace Emby.Server.Core
{
get
{
#if DEBUG
return false;
#endif
#pragma warning disable 162
return NativeApp.CanSelfUpdate;
#pragma warning restore 162

View File

@ -100,7 +100,12 @@ namespace Emby.Server.Implementations.HttpServer.SocketSharp
{
var outputStream = response.OutputStream;
outputStream.Flush();
// This is needed with compression
//if (!string.IsNullOrWhiteSpace(GetHeader("Content-Encoding")))
{
outputStream.Flush();
}
outputStream.Dispose();
response.Close();
}

View File

@ -291,6 +291,10 @@ namespace MediaBrowser.ServerApplication
{
get
{
#if DEBUG
return false;
#endif
if (_isRunningAsService)
{
return _canRestartService;

View File

@ -23,7 +23,7 @@ namespace SocketHttpListener.Net
StringBuilder current_line;
ListenerPrefix prefix;
RequestStream i_stream;
ResponseStream o_stream;
Stream o_stream;
bool chunked;
int reuses;
bool context_bound;
@ -204,12 +204,23 @@ namespace SocketHttpListener.Net
return i_stream;
}
public ResponseStream GetResponseStream()
public Stream GetResponseStream()
{
// TODO: can we get this stream before reading the input?
if (o_stream == null)
{
o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding);
if (context.Response.SendChunked)
{
o_stream = new ResponseStream(stream, context.Response, _memoryStreamFactory, _textEncoding);
}
else
{
o_stream = stream;
using (var headerStream = ResponseStream.GetHeaders(context.Response, _memoryStreamFactory, false))
{
headerStream.CopyTo(o_stream);
}
}
}
return o_stream;
}

View File

@ -181,11 +181,11 @@ namespace SocketHttpListener.Net
if (String.Compare(Headers["Expect"], "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
{
ResponseStream output = context.Connection.GetResponseStream();
var output = context.Connection.GetResponseStream();
var _100continue = _textEncoding.GetASCIIEncoding().GetBytes("HTTP/1.1 100 Continue\r\n\r\n");
output.InternalWrite(_100continue, 0, _100continue.Length);
//output.InternalWrite(_100continue, 0, _100continue.Length);
}
}

View File

@ -19,7 +19,7 @@ namespace SocketHttpListener.Net
CookieCollection cookies;
WebHeaderCollection headers = new WebHeaderCollection();
bool keep_alive = true;
ResponseStream output_stream;
Stream output_stream;
Version version = HttpVersion.Version11;
string location;
int status_code = 200;

View File

@ -64,7 +64,7 @@ namespace SocketHttpListener.Net
{
disposed = true;
byte[] bytes = null;
MemoryStream ms = GetHeaders(true);
MemoryStream ms = GetHeaders(response, _memoryStreamFactory, false);
bool chunked = response.SendChunked;
if (stream.CanWrite)
{
@ -102,14 +102,14 @@ namespace SocketHttpListener.Net
base.Dispose(disposing);
}
MemoryStream GetHeaders(bool closing)
internal static MemoryStream GetHeaders(HttpListenerResponse response, IMemoryStreamFactory memoryStreamFactory, bool closing)
{
// SendHeaders works on shared headers
lock (response.headers_lock)
{
if (response.HeadersSent)
return null;
MemoryStream ms = _memoryStreamFactory.CreateNew();
MemoryStream ms = memoryStreamFactory.CreateNew();
response.SendHeaders(closing, ms);
return ms;
}
@ -137,7 +137,7 @@ namespace SocketHttpListener.Net
throw new ObjectDisposedException(GetType().ToString());
byte[] bytes = null;
MemoryStream ms = GetHeaders(false);
MemoryStream ms = GetHeaders(response, _memoryStreamFactory, false);
bool chunked = response.SendChunked;
if (ms != null)
{
@ -177,7 +177,7 @@ namespace SocketHttpListener.Net
throw new ObjectDisposedException(GetType().ToString());
byte[] bytes = null;
MemoryStream ms = GetHeaders(false);
MemoryStream ms = GetHeaders(response, _memoryStreamFactory, false);
bool chunked = response.SendChunked;
if (ms != null)
{