diff options
Diffstat (limited to 'Emby.Server.Implementations/Services')
3 files changed, 13 insertions, 25 deletions
diff --git a/Emby.Server.Implementations/Services/ResponseHelper.cs b/Emby.Server.Implementations/Services/ResponseHelper.cs index 22d2b95f7f..84dc343c39 100644 --- a/Emby.Server.Implementations/Services/ResponseHelper.cs +++ b/Emby.Server.Implementations/Services/ResponseHelper.cs @@ -12,39 +12,28 @@ namespace Emby.Server.Implementations.Services { public static class ResponseHelper { - public static Task WriteToResponse(IResponse httpRes, IRequest httpReq, object result, CancellationToken cancellationToken) + public static async Task WriteToResponse(IResponse response, IRequest request, object result, CancellationToken cancellationToken) { if (result == null) { - if (httpRes.StatusCode == (int)HttpStatusCode.OK) + if (response.StatusCode == (int)HttpStatusCode.OK) { - httpRes.StatusCode = (int)HttpStatusCode.NoContent; + response.StatusCode = (int)HttpStatusCode.NoContent; } - httpRes.SetContentLength(0); - return Task.FromResult(true); + response.SetContentLength(0); + return; } var httpResult = result as IHttpResult; if (httpResult != null) { - httpResult.RequestContext = httpReq; - httpReq.ResponseContentType = httpResult.ContentType ?? httpReq.ResponseContentType; - return WriteToResponseInternal(httpRes, httpResult, httpReq, cancellationToken); + httpResult.RequestContext = request; + request.ResponseContentType = httpResult.ContentType ?? request.ResponseContentType; } - return WriteToResponseInternal(httpRes, result, httpReq, cancellationToken); - } - - /// <summary> - /// Writes to response. - /// Response headers are customizable by implementing IHasHeaders an returning Dictionary of Http headers. - /// </summary> - private static async Task WriteToResponseInternal(IResponse response, object result, IRequest request, CancellationToken cancellationToken) - { var defaultContentType = request.ResponseContentType; - var httpResult = result as IHttpResult; if (httpResult != null) { if (httpResult.RequestContext == null) @@ -135,7 +124,7 @@ namespace Emby.Server.Implementations.Services response.ContentType = "application/octet-stream"; response.SetContentLength(bytes.Length); - await response.OutputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); + await response.OutputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false); return; } @@ -144,7 +133,7 @@ namespace Emby.Server.Implementations.Services { bytes = Encoding.UTF8.GetBytes(responseText); response.SetContentLength(bytes.Length); - await response.OutputStream.WriteAsync(bytes, 0, bytes.Length).ConfigureAwait(false); + await response.OutputStream.WriteAsync(bytes, 0, bytes.Length, cancellationToken).ConfigureAwait(false); return; } diff --git a/Emby.Server.Implementations/Services/ServiceController.cs b/Emby.Server.Implementations/Services/ServiceController.cs index d283bf81f6..1c530144c9 100644 --- a/Emby.Server.Implementations/Services/ServiceController.cs +++ b/Emby.Server.Implementations/Services/ServiceController.cs @@ -187,7 +187,7 @@ namespace Emby.Server.Implementations.Services return null; } - public async Task<object> Execute(HttpListenerHost appHost, object requestDto, IRequest req) + public Task<object> Execute(HttpListenerHost appHost, object requestDto, IRequest req) { req.Dto = requestDto; var requestType = requestDto.GetType(); @@ -209,9 +209,7 @@ namespace Emby.Server.Implementations.Services req.Dto = requestDto; //Executes the service and returns the result - var response = await ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetMethodName()).ConfigureAwait(false); - - return response; + return ServiceExecGeneral.Execute(serviceType, req, service, requestDto, requestType.GetMethodName()); } } diff --git a/Emby.Server.Implementations/Services/ServiceHandler.cs b/Emby.Server.Implementations/Services/ServiceHandler.cs index 95a9dd6829..526e62d398 100644 --- a/Emby.Server.Implementations/Services/ServiceHandler.cs +++ b/Emby.Server.Implementations/Services/ServiceHandler.cs @@ -143,7 +143,8 @@ namespace Emby.Server.Implementations.Services var rawResponse = await appHost.ServiceController.Execute(appHost, request, httpReq).ConfigureAwait(false); - var response = await HandleResponseAsync(rawResponse).ConfigureAwait(false); + //var response = await HandleResponseAsync(rawResponse).ConfigureAwait(false); + var response = rawResponse; // Apply response filters foreach (var responseFilter in appHost.ResponseFilters) |
