Don't set status code if response is closed

pull/1065/head
Claus Vium 6 years ago
parent 10a0d6bdba
commit 3fa43a1e08

@ -225,7 +225,7 @@ namespace Emby.Server.Implementations.HttpServer
var httpRes = httpReq.Response;
if (httpRes.IsClosed)
if (httpRes.OriginalResponse.HasStarted)
{
return;
}
@ -595,8 +595,6 @@ namespace Emby.Server.Implementations.HttpServer
}
finally
{
// TODO response closes automatically after the handler is done, but some functions rely on knowing if it's closed or not
httpRes.IsClosed = true;
stopWatch.Stop();
var elapsed = stopWatch.Elapsed;
if (elapsed.TotalMilliseconds > 500)

@ -78,7 +78,7 @@ namespace Emby.Server.Implementations.Services
foreach (var requestFilter in actionContext.RequestFilters)
{
requestFilter.RequestFilter(request, request.Response, requestDto);
if (request.Response.IsClosed)
if (request.Response.OriginalResponse.HasStarted)
{
Task.FromResult<object>(null);
}

@ -90,7 +90,10 @@ namespace Emby.Server.Implementations.SocketSharp
catch (Exception ex)
{
_logger.LogError(ex, "AcceptWebSocketAsync error");
ctx.Response.StatusCode = 500;
if (!ctx.Response.HasStarted)
{
ctx.Response.StatusCode = 500;
}
}
}

@ -20,22 +20,19 @@ namespace Emby.Server.Implementations.SocketSharp
public partial class WebSocketSharpRequest : IHttpRequest
{
private readonly HttpRequest request;
private readonly IResponse response;
public WebSocketSharpRequest(HttpRequest httpContext, HttpResponse response, string operationName, ILogger logger)
{
this.OperationName = operationName;
this.request = httpContext;
this.response = new WebSocketSharpResponse(logger, response, this);
this.Response = new WebSocketSharpResponse(logger, response);
// HandlerFactoryPath = GetHandlerPathIfAny(UrlPrefixes[0]);
}
public HttpRequest HttpRequest => request;
public IResponse Response => response;
public IResponse HttpResponse => response;
public IResponse Response { get; }
public string OperationName { get; set; }

@ -16,38 +16,28 @@ namespace Emby.Server.Implementations.SocketSharp
{
private readonly ILogger _logger;
private readonly HttpResponse _response;
public WebSocketSharpResponse(ILogger logger, HttpResponse response, IRequest request)
public WebSocketSharpResponse(ILogger logger, HttpResponse response)
{
_logger = logger;
this._response = response;
Items = new Dictionary<string, object>();
Request = request;
OriginalResponse = response;
}
public IRequest Request { get; private set; }
public Dictionary<string, object> Items { get; private set; }
public object OriginalResponse => _response;
public HttpResponse OriginalResponse { get; }
public int StatusCode
{
get => this._response.StatusCode;
set => this._response.StatusCode = value;
get => OriginalResponse.StatusCode;
set => OriginalResponse.StatusCode = value;
}
public string StatusDescription { get; set; }
public string ContentType
{
get => _response.ContentType;
set => _response.ContentType = value;
get => OriginalResponse.ContentType;
set => OriginalResponse.ContentType = value;
}
public IHeaderDictionary Headers => _response.Headers;
public void AddHeader(string name, string value)
{
if (string.Equals(name, "Content-Type", StringComparison.OrdinalIgnoreCase))
@ -56,22 +46,15 @@ namespace Emby.Server.Implementations.SocketSharp
return;
}
_response.Headers.Add(name, value);
}
public string GetHeader(string name)
{
return _response.Headers[name];
OriginalResponse.Headers.Add(name, value);
}
public void Redirect(string url)
{
_response.Redirect(url);
OriginalResponse.Redirect(url);
}
public Stream OutputStream => _response.Body;
public bool IsClosed { get; set; }
public Stream OutputStream => OriginalResponse.Body;
public bool SendChunked { get; set; }

@ -101,7 +101,7 @@ namespace MediaBrowser.Model.Services
public interface IResponse
{
IRequest Request { get; }
HttpResponse OriginalResponse { get; }
int StatusCode { get; set; }
@ -111,22 +111,10 @@ namespace MediaBrowser.Model.Services
void AddHeader(string name, string value);
string GetHeader(string name);
void Redirect(string url);
Stream OutputStream { get; }
/// <summary>
/// Gets a value indicating whether this instance is closed.
/// </summary>
bool IsClosed { get; set; }
//Add Metadata to Response
Dictionary<string, object> Items { get; }
IHeaderDictionary Headers { get; }
Task TransmitFile(string path, long offset, long count, FileShareMode fileShareMode, IFileSystem fileSystem, IStreamHelper streamHelper, CancellationToken cancellationToken);
bool SendChunked { get; set; }

Loading…
Cancel
Save