From 17d01636ae8a8054dc1fc043315f4fb2f4d53187 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Tue, 12 Mar 2013 23:57:54 -0400 Subject: #41 - Support Http Head requests --- .../HttpServer/BaseRestService.cs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'MediaBrowser.Server.Implementations/HttpServer/BaseRestService.cs') diff --git a/MediaBrowser.Server.Implementations/HttpServer/BaseRestService.cs b/MediaBrowser.Server.Implementations/HttpServer/BaseRestService.cs index 0445cd863..baa5b0888 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/BaseRestService.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/BaseRestService.cs @@ -132,14 +132,15 @@ namespace MediaBrowser.Server.Implementations.HttpServer return factoryFn(); } - + /// /// To the static file result. /// /// The path. + /// if set to true [headers only]. /// System.Object. /// path - protected object ToStaticFileResult(string path) + protected object ToStaticFileResult(string path, bool headersOnly = false) { if (string.IsNullOrEmpty(path)) { @@ -150,7 +151,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer var cacheKey = path + dateModified.Ticks; - return ToStaticResult(cacheKey.GetMD5(), dateModified, null, MimeTypes.GetMimeType(path), () => Task.FromResult(GetFileStream(path))); + return ToStaticResult(cacheKey.GetMD5(), dateModified, null, MimeTypes.GetMimeType(path), () => Task.FromResult(GetFileStream(path)), headersOnly); } /// @@ -162,7 +163,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer { return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); } - + /// /// To the static result. /// @@ -171,9 +172,10 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// Duration of the cache. /// Type of the content. /// The factory fn. + /// if set to true [headers only]. /// System.Object. /// cacheKey - protected object ToStaticResult(Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, string contentType, Func> factoryFn) + protected object ToStaticResult(Guid cacheKey, DateTime? lastDateModified, TimeSpan? cacheDuration, string contentType, Func> factoryFn, bool headersOnly = false) { if (cacheKey == Guid.Empty) { @@ -203,7 +205,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer Response.AddHeader("Vary", "Accept-Encoding"); } - return ToStaticResult(contentType, factoryFn, compress).Result; + return ToStaticResult(contentType, factoryFn, compress, headersOnly).Result; } /// @@ -249,8 +251,9 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// Type of the content. /// The factory fn. /// if set to true [compress]. + /// if set to true [headers only]. /// System.Object. - private async Task ToStaticResult(string contentType, Func> factoryFn, bool compress) + private async Task ToStaticResult(string contentType, Func> factoryFn, bool compress, bool headersOnly = false) { if (!compress || string.IsNullOrEmpty(RequestContext.CompressionType)) { @@ -263,7 +266,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer if (IsRangeRequest) { - return new RangeRequestWriter(Request.Headers, httpListenerResponse, stream); + return new RangeRequestWriter(Request.Headers, httpListenerResponse, stream, headersOnly); } httpListenerResponse.ContentLength64 = stream.Length; -- cgit v1.2.3