From ebec1e159c22131bf6fed1c807595894f92427ae Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 15 Sep 2013 13:34:37 -0400 Subject: update default theme endpoints --- .../HttpServer/HttpResultFactory.cs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 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 115114e3a..356c6fc4d 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Server.Implementations.HttpServer { AddResponseHeaders(result, responseHeaders); } - + return result; } @@ -271,32 +271,39 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// /// The request context. /// The path. + /// The file share. /// The response headers. /// if set to true [is head request]. /// System.Object. /// path - public object GetStaticFileResult(IRequestContext requestContext, string path, IDictionary responseHeaders = null, bool isHeadRequest = false) + public object GetStaticFileResult(IRequestContext requestContext, string path, FileShare fileShare = FileShare.Read, IDictionary responseHeaders = null, bool isHeadRequest = false) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } + if (fileShare != FileShare.Read && fileShare != FileShare.ReadWrite) + { + throw new ArgumentException("FileShare must be either Read or ReadWrite"); + } + var dateModified = File.GetLastWriteTimeUtc(path); var cacheKey = path + dateModified.Ticks; - return GetStaticResult(requestContext, cacheKey.GetMD5(), dateModified, null, MimeTypes.GetMimeType(path), () => Task.FromResult(GetFileStream(path)), responseHeaders, isHeadRequest); + return GetStaticResult(requestContext, cacheKey.GetMD5(), dateModified, null, MimeTypes.GetMimeType(path), () => Task.FromResult(GetFileStream(path, fileShare)), responseHeaders, isHeadRequest); } /// /// Gets the file stream. /// /// The path. + /// The file share. /// Stream. - private Stream GetFileStream(string path) + private Stream GetFileStream(string path, FileShare fileShare) { - return new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); + return new FileStream(path, FileMode.Open, FileAccess.Read, fileShare, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous); } /// -- cgit v1.2.3