diff options
Diffstat (limited to 'MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs')
| -rw-r--r-- | MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs | 87 |
1 files changed, 30 insertions, 57 deletions
diff --git a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs index 741d2d6c1..11438b164 100644 --- a/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs +++ b/MediaBrowser.Common/Net/Handlers/StaticFileHandler.cs @@ -33,46 +33,7 @@ namespace MediaBrowser.Common.Net.Handlers }
}
- private bool _sourceStreamEnsured;
- private Stream _sourceStream;
- private Stream SourceStream
- {
- get
- {
- EnsureSourceStream();
- return _sourceStream;
- }
- }
-
- private void EnsureSourceStream()
- {
- if (!_sourceStreamEnsured)
- {
- try
- {
- _sourceStream = File.OpenRead(Path);
- }
- catch (FileNotFoundException ex)
- {
- StatusCode = 404;
- Logger.LogException(ex);
- }
- catch (DirectoryNotFoundException ex)
- {
- StatusCode = 404;
- Logger.LogException(ex);
- }
- catch (UnauthorizedAccessException ex)
- {
- StatusCode = 403;
- Logger.LogException(ex);
- }
- finally
- {
- _sourceStreamEnsured = true;
- }
- }
- }
+ private Stream SourceStream { get; set; }
protected override bool SupportsByteRangeRequests
{
@@ -82,7 +43,7 @@ namespace MediaBrowser.Common.Net.Handlers }
}
- public override bool ShouldCompressResponse(string contentType)
+ private bool ShouldCompressResponse(string contentType)
{
// Can't compress these
if (IsRangeRequest)
@@ -105,29 +66,41 @@ namespace MediaBrowser.Common.Net.Handlers return SourceStream.Length;
}
- protected override Task<DateTime?> GetLastDateModified()
+ protected override Task<ResponseInfo> GetResponseInfo()
{
- DateTime? value = null;
-
- EnsureSourceStream();
+ ResponseInfo info = new ResponseInfo
+ {
+ ContentType = MimeTypes.GetMimeType(Path),
+ };
- if (SourceStream != null)
+ try
+ {
+ SourceStream = File.OpenRead(Path);
+ }
+ catch (FileNotFoundException ex)
+ {
+ info.StatusCode = 404;
+ Logger.LogException(ex);
+ }
+ catch (DirectoryNotFoundException ex)
{
- value = File.GetLastWriteTimeUtc(Path);
+ info.StatusCode = 404;
+ Logger.LogException(ex);
+ }
+ catch (UnauthorizedAccessException ex)
+ {
+ info.StatusCode = 403;
+ Logger.LogException(ex);
}
- return Task.FromResult(value);
- }
+ info.CompressResponse = ShouldCompressResponse(info.ContentType);
- public override Task<string> GetContentType()
- {
- return Task.FromResult(MimeTypes.GetMimeType(Path));
- }
+ if (SourceStream != null)
+ {
+ info.DateLastModified = File.GetLastWriteTimeUtc(Path);
+ }
- protected override Task PrepareResponse()
- {
- EnsureSourceStream();
- return Task.FromResult<object>(null);
+ return Task.FromResult<ResponseInfo>(info);
}
protected override Task WriteResponseToOutputStream(Stream stream)
|
