From 6a9dbf6ae85b4e7abcf06f7f29ef9d8b0b890876 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 29 Aug 2014 08:14:41 -0400 Subject: update translations --- .../HttpServer/HttpResultFactory.cs | 68 ++++++++++++++++------ 1 file changed, 50 insertions(+), 18 deletions(-) (limited to 'MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs') diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 6a60e5ea6..be3e5f005 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -298,8 +298,13 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// The response headers. /// if set to true [is head request]. /// System.Object. + /// path /// path - public object GetStaticFileResult(IRequest requestContext, string path, FileShare fileShare = FileShare.Read, IDictionary responseHeaders = null, bool isHeadRequest = false) + public object GetStaticFileResult(IRequest requestContext, + string path, + FileShare fileShare = FileShare.Read, + IDictionary responseHeaders = null, + bool isHeadRequest = false) { if (string.IsNullOrEmpty(path)) { @@ -309,13 +314,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer return GetStaticFileResult(requestContext, path, MimeTypes.GetMimeType(path), null, fileShare, responseHeaders, isHeadRequest); } - public object GetStaticFileResult(IRequest requestContext, - string path, + public object GetStaticFileResult(IRequest requestContext, + string path, string contentType, TimeSpan? cacheCuration = null, - FileShare fileShare = FileShare.Read, + FileShare fileShare = FileShare.Read, IDictionary responseHeaders = null, - bool isHeadRequest = false) + bool isHeadRequest = false, + bool throttle = false, + long throttleLimit = 0) { if (string.IsNullOrEmpty(path)) { @@ -331,7 +338,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer var cacheKey = path + dateModified.Ticks; - return GetStaticResult(requestContext, cacheKey.GetMD5(), dateModified, cacheCuration, contentType, () => Task.FromResult(GetFileStream(path, fileShare)), responseHeaders, isHeadRequest); + return GetStaticResult(requestContext, cacheKey.GetMD5(), dateModified, cacheCuration, contentType, () => Task.FromResult(GetFileStream(path, fileShare)), responseHeaders, isHeadRequest, throttle, throttleLimit); } /// @@ -360,7 +367,29 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// cacheKey /// or /// factoryFn - public object GetStaticResult(IRequest requestContext, Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, string contentType, Func> factoryFn, IDictionary responseHeaders = null, bool isHeadRequest = false) + public object GetStaticResult(IRequest requestContext, + Guid cacheKey, + DateTime? lastDateModified, + TimeSpan? cacheDuration, + string contentType, + Func> factoryFn, + IDictionary responseHeaders = null, + bool isHeadRequest = false) + { + return GetStaticResult(requestContext, cacheKey, lastDateModified, cacheDuration, contentType, factoryFn, + responseHeaders, isHeadRequest, false, 0); + } + + public object GetStaticResult(IRequest requestContext, + Guid cacheKey, + DateTime? lastDateModified, + TimeSpan? cacheDuration, + string contentType, + Func> factoryFn, + IDictionary responseHeaders = null, + bool isHeadRequest = false, + bool throttle = false, + long throttleLimit = 0) { if (cacheKey == Guid.Empty) { @@ -386,15 +415,8 @@ namespace MediaBrowser.Server.Implementations.HttpServer return result; } - return GetNonCachedResult(requestContext, contentType, factoryFn, responseHeaders, isHeadRequest); - } - - private async Task GetNonCachedResult(IRequest requestContext, string contentType, Func> factoryFn, IDictionary responseHeaders = null, bool isHeadRequest = false) - { var compress = ShouldCompressResponse(requestContext, contentType); - - var hasOptions = await GetStaticResult(requestContext, responseHeaders, contentType, factoryFn, compress, isHeadRequest).ConfigureAwait(false); - + var hasOptions = GetStaticResult(requestContext, responseHeaders, contentType, factoryFn, compress, isHeadRequest, throttle, throttleLimit).Result; AddResponseHeaders(hasOptions, responseHeaders); return hasOptions; @@ -460,8 +482,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// The factory fn. /// if set to true [compress]. /// if set to true [is head request]. + /// if set to true [throttle]. + /// The throttle limit. /// Task{IHasOptions}. - private async Task GetStaticResult(IRequest requestContext, IDictionary responseHeaders, string contentType, Func> factoryFn, bool compress, bool isHeadRequest) + private async Task GetStaticResult(IRequest requestContext, IDictionary responseHeaders, string contentType, Func> factoryFn, bool compress, bool isHeadRequest, bool throttle, long throttleLimit = 0) { var requestedCompressionType = requestContext.GetCompressionType(); @@ -473,7 +497,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (!string.IsNullOrEmpty(rangeHeader)) { - return new RangeRequestWriter(rangeHeader, stream, contentType, isHeadRequest); + return new RangeRequestWriter(rangeHeader, stream, contentType, isHeadRequest) + { + Throttle = throttle, + ThrottleLimit = throttleLimit + }; } responseHeaders["Content-Length"] = stream.Length.ToString(UsCulture); @@ -485,7 +513,11 @@ namespace MediaBrowser.Server.Implementations.HttpServer return GetHttpResult(new byte[] { }, contentType); } - return new StreamWriter(stream, contentType, _logger); + return new StreamWriter(stream, contentType, _logger) + { + Throttle = throttle, + ThrottleLimit = throttleLimit + }; } string content; -- cgit v1.2.3