aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
diff options
context:
space:
mode:
authorBond_009 <bond.009@outlook.com>2019-01-06 20:35:36 +0100
committerBond_009 <bond.009@outlook.com>2019-01-06 20:35:36 +0100
commit07a8e49c4b1e4a2dddbaa49ab6f1ff4f271fbf20 (patch)
tree86cc8c77ebf98985cfa8f4727f0f900d24219042 /Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
parentb27315bc08d4d224cf090efc24385c7102741089 (diff)
Cleanup some small things
Diffstat (limited to 'Emby.Server.Implementations/HttpServer/HttpResultFactory.cs')
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpResultFactory.cs39
1 files changed, 15 insertions, 24 deletions
diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
index 73b2afe64..3d0fb577a 100644
--- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs
@@ -412,8 +412,10 @@ namespace Emby.Server.Implementations.HttpServer
serializer.WriteObject(xw, from);
xw.Flush();
ms.Seek(0, SeekOrigin.Begin);
- var reader = new StreamReader(ms);
- return reader.ReadToEnd();
+ using (var reader = new StreamReader(ms))
+ {
+ return reader.ReadToEnd();
+ }
}
}
}
@@ -425,7 +427,7 @@ namespace Emby.Server.Implementations.HttpServer
{
responseHeaders["ETag"] = string.Format("\"{0}\"", cacheKeyString);
- var noCache = (requestContext.Headers.Get("Cache-Control") ?? string.Empty).IndexOf("no-cache", StringComparison.OrdinalIgnoreCase) != -1;
+ bool noCache = (requestContext.Headers.Get("Cache-Control") ?? string.Empty).IndexOf("no-cache", StringComparison.OrdinalIgnoreCase) != -1;
if (!noCache)
{
@@ -463,8 +465,7 @@ namespace Emby.Server.Implementations.HttpServer
});
}
- public Task<object> GetStaticFileResult(IRequest requestContext,
- StaticFileResultOptions options)
+ public Task<object> GetStaticFileResult(IRequest requestContext, StaticFileResultOptions options)
{
var path = options.Path;
var fileShare = options.FileShare;
@@ -699,36 +700,26 @@ namespace Emby.Server.Implementations.HttpServer
var ifModifiedSinceHeader = requestContext.Headers.Get("If-Modified-Since");
- if (!string.IsNullOrEmpty(ifModifiedSinceHeader))
+ if (!string.IsNullOrEmpty(ifModifiedSinceHeader)
+ && DateTime.TryParse(ifModifiedSinceHeader, out DateTime ifModifiedSince)
+ && IsNotModified(ifModifiedSince.ToUniversalTime(), cacheDuration, lastDateModified))
{
- DateTime ifModifiedSince;
-
- if (DateTime.TryParse(ifModifiedSinceHeader, out ifModifiedSince))
- {
- if (IsNotModified(ifModifiedSince.ToUniversalTime(), cacheDuration, lastDateModified))
- {
- return true;
- }
- }
+ return true;
}
var ifNoneMatchHeader = requestContext.Headers.Get("If-None-Match");
- var hasCacheKey = !cacheKey.Equals(Guid.Empty);
+ bool hasCacheKey = !cacheKey.Equals(Guid.Empty);
// Validate If-None-Match
- if ((hasCacheKey || !string.IsNullOrEmpty(ifNoneMatchHeader)))
+ if ((hasCacheKey && !string.IsNullOrEmpty(ifNoneMatchHeader)))
{
- Guid ifNoneMatch;
-
ifNoneMatchHeader = (ifNoneMatchHeader ?? string.Empty).Trim('\"');
- if (Guid.TryParse(ifNoneMatchHeader, out ifNoneMatch))
+ if (Guid.TryParse(ifNoneMatchHeader, out Guid ifNoneMatch)
+ && cacheKey.Equals(ifNoneMatch))
{
- if (hasCacheKey && cacheKey.Equals(ifNoneMatch))
- {
- return true;
- }
+ return true;
}
}