mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 18:08:53 -07:00
Merge pull request #1065 from cvium/closed_response
Don't set status code if response is closed
This commit is contained in:
commit
669c48cc8b
@ -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,9 +90,12 @@ namespace Emby.Server.Implementations.SocketSharp
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "AcceptWebSocketAsync error");
|
||||
if (!ctx.Response.HasStarted)
|
||||
{
|
||||
ctx.Response.StatusCode = 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task Stop()
|
||||
{
|
||||
|
@ -19,22 +19,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…
Reference in New Issue
Block a user