diff options
Diffstat (limited to 'Emby.Server.Implementations/Services')
3 files changed, 18 insertions, 33 deletions
diff --git a/Emby.Server.Implementations/Services/ResponseHelper.cs b/Emby.Server.Implementations/Services/ResponseHelper.cs index 3c2af60db..84dc343c3 100644 --- a/Emby.Server.Implementations/Services/ResponseHelper.cs +++ b/Emby.Server.Implementations/Services/ResponseHelper.cs @@ -12,43 +12,28 @@ namespace Emby.Server.Implementations.Services { public static class ResponseHelper { - public static Task WriteToResponse(IResponse httpRes, IRequest httpReq, object result) + 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); + httpResult.RequestContext = request; + request.ResponseContentType = httpResult.ContentType ?? request.ResponseContentType; } - return WriteToResponseInternal(httpRes, result, httpReq); - } - - /// <summary> - /// Writes to response. - /// Response headers are customizable by implementing IHasHeaders an returning Dictionary of Http headers. - /// </summary> - /// <param name="response">The response.</param> - /// <param name="result">Whether or not it was implicity handled by ServiceStack's built-in handlers.</param> - /// <param name="request">The serialization context.</param> - /// <returns></returns> - private static async Task WriteToResponseInternal(IResponse response, object result, IRequest request) - { var defaultContentType = request.ResponseContentType; - var httpResult = result as IHttpResult; if (httpResult != null) { if (httpResult.RequestContext == null) @@ -105,7 +90,7 @@ namespace Emby.Server.Implementations.Services var asyncStreamWriter = result as IAsyncStreamWriter; if (asyncStreamWriter != null) { - await asyncStreamWriter.WriteToAsync(response.OutputStream, CancellationToken.None).ConfigureAwait(false); + await asyncStreamWriter.WriteToAsync(response.OutputStream, cancellationToken).ConfigureAwait(false); return; } @@ -119,7 +104,7 @@ namespace Emby.Server.Implementations.Services var fileWriter = result as FileWriter; if (fileWriter != null) { - await fileWriter.WriteToAsync(response, CancellationToken.None).ConfigureAwait(false); + await fileWriter.WriteToAsync(response, cancellationToken).ConfigureAwait(false); return; } @@ -139,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; } @@ -148,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 d283bf81f..1c530144c 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 8b59b4843..526e62d39 100644 --- a/Emby.Server.Implementations/Services/ServiceHandler.cs +++ b/Emby.Server.Implementations/Services/ServiceHandler.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Reflection; +using System.Threading; using System.Threading.Tasks; using Emby.Server.Implementations.HttpServer; using MediaBrowser.Model.Logging; @@ -123,7 +124,7 @@ namespace Emby.Server.Implementations.Services // Set from SSHHF.GetHandlerForPathInfo() public string ResponseContentType { get; set; } - public async Task ProcessRequestAsync(HttpListenerHost appHost, IRequest httpReq, IResponse httpRes, ILogger logger, string operationName) + public async Task ProcessRequestAsync(HttpListenerHost appHost, IRequest httpReq, IResponse httpRes, ILogger logger, string operationName, CancellationToken cancellationToken) { var restPath = GetRestPath(httpReq.Verb, httpReq.PathInfo); if (restPath == null) @@ -142,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) @@ -150,7 +152,7 @@ namespace Emby.Server.Implementations.Services responseFilter(httpReq, httpRes, response); } - await ResponseHelper.WriteToResponse(httpRes, httpReq, response).ConfigureAwait(false); + await ResponseHelper.WriteToResponse(httpRes, httpReq, response, cancellationToken).ConfigureAwait(false); } public static object CreateRequest(HttpListenerHost host, IRequest httpReq, RestPath restPath, ILogger logger) |
