update response stream handling

pull/702/head
Luke Pulverenti 8 years ago
parent 6865bb5353
commit 1714cb8764

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

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

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

@ -23,7 +23,7 @@ namespace SocketHttpListener.Net
StringBuilder current_line; StringBuilder current_line;
ListenerPrefix prefix; ListenerPrefix prefix;
RequestStream i_stream; RequestStream i_stream;
ResponseStream o_stream; Stream o_stream;
bool chunked; bool chunked;
int reuses; int reuses;
bool context_bound; bool context_bound;
@ -204,12 +204,23 @@ namespace SocketHttpListener.Net
return i_stream; return i_stream;
} }
public ResponseStream GetResponseStream() public Stream GetResponseStream()
{ {
// 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)
{ {
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; return o_stream;
} }

@ -181,11 +181,11 @@ namespace SocketHttpListener.Net
if (String.Compare(Headers["Expect"], "100-continue", StringComparison.OrdinalIgnoreCase) == 0) 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"); 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);
} }
} }

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

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

Loading…
Cancel
Save