aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/HttpHandlers
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api/HttpHandlers')
-rw-r--r--MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs13
-rw-r--r--MediaBrowser.Api/HttpHandlers/ImageHandler.cs71
-rw-r--r--MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs4
-rw-r--r--MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs19
-rw-r--r--MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs19
-rw-r--r--MediaBrowser.Api/HttpHandlers/WeatherHandler.cs16
6 files changed, 46 insertions, 96 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs b/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs
index 7ad0ed8aa..96ef60681 100644
--- a/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs
+++ b/MediaBrowser.Api/HttpHandlers/BaseMediaHandler.cs
@@ -90,14 +90,15 @@ namespace MediaBrowser.Api.HttpHandlers
}
}
- public override Task<string> GetContentType()
+ protected override Task<ResponseInfo> GetResponseInfo()
{
- return Task.FromResult(MimeTypes.GetMimeType("." + GetConversionOutputFormat()));
- }
+ ResponseInfo info = new ResponseInfo
+ {
+ ContentType = MimeTypes.GetMimeType("." + GetConversionOutputFormat()),
+ CompressResponse = false
+ };
- public override bool ShouldCompressResponse(string contentType)
- {
- return false;
+ return Task.FromResult<ResponseInfo>(info);
}
public override Task ProcessRequest(HttpListenerContext ctx)
diff --git a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs
index d3aaf27ff..4aa367fb7 100644
--- a/MediaBrowser.Api/HttpHandlers/ImageHandler.cs
+++ b/MediaBrowser.Api/HttpHandlers/ImageHandler.cs
@@ -7,7 +7,6 @@ using MediaBrowser.Model.Entities;
using System;
using System.ComponentModel.Composition;
using System.IO;
-using System.Linq;
using System.Net;
using System.Threading.Tasks;
@@ -82,76 +81,32 @@ namespace MediaBrowser.Api.HttpHandlers
return ImageProcessor.GetImagePath(entity, ImageType, ImageIndex);
}
- public override async Task<string> GetContentType()
- {
- if (Kernel.Instance.ImageProcessors.Any(i => i.RequiresTransparency))
- {
- return MimeTypes.GetMimeType(".png");
- }
-
- return MimeTypes.GetMimeType(await GetImagePath().ConfigureAwait(false));
- }
-
- public override TimeSpan CacheDuration
- {
- get { return TimeSpan.FromDays(365); }
- }
-
- protected override async Task<DateTime?> GetLastDateModified()
+ protected async override Task<ResponseInfo> GetResponseInfo()
{
string path = await GetImagePath().ConfigureAwait(false);
- DateTime date = File.GetLastWriteTimeUtc(path);
+ ResponseInfo info = new ResponseInfo
+ {
+ CacheDuration = TimeSpan.FromDays(365),
+ ContentType = MimeTypes.GetMimeType(path)
+ };
+
+ DateTime? date = File.GetLastWriteTimeUtc(path);
// If the file does not exist it will return jan 1, 1601
// http://msdn.microsoft.com/en-us/library/system.io.file.getlastwritetimeutc.aspx
- if (date.Year == 1601)
+ if (date.Value.Year == 1601)
{
if (!File.Exists(path))
{
- StatusCode = 404;
- return null;
- }
- }
-
- return await GetMostRecentDateModified(date);
- }
-
- private async Task<DateTime> GetMostRecentDateModified(DateTime imageFileLastDateModified)
- {
- var date = imageFileLastDateModified;
-
- var entity = await GetSourceEntity().ConfigureAwait(false);
-
- foreach (var processor in Kernel.Instance.ImageProcessors)
- {
- if (processor.IsConfiguredToProcess(entity, ImageType, ImageIndex))
- {
- if (processor.ProcessingConfigurationDateLastModifiedUtc > date)
- {
- date = processor.ProcessingConfigurationDateLastModifiedUtc;
- }
+ info.StatusCode = 404;
+ date = null;
}
}
- return date;
- }
-
- protected override async Task<string> GetETag()
- {
- string tag = string.Empty;
-
- var entity = await GetSourceEntity().ConfigureAwait(false);
-
- foreach (var processor in Kernel.Instance.ImageProcessors)
- {
- if (processor.IsConfiguredToProcess(entity, ImageType, ImageIndex))
- {
- tag += processor.ProcessingConfigurationDateLastModifiedUtc.Ticks.ToString();
- }
- }
+ info.DateLastModified = date;
- return tag;
+ return info;
}
private int ImageIndex
diff --git a/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs
index 88161c114..47f08c8c3 100644
--- a/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs
+++ b/MediaBrowser.Api/HttpHandlers/PluginAssemblyHandler.cs
@@ -15,8 +15,8 @@ namespace MediaBrowser.Api.HttpHandlers
{
return ApiService.IsApiUrlMatch("pluginassembly", request);
}
-
- public override Task<string> GetContentType()
+
+ protected override Task<ResponseInfo> GetResponseInfo()
{
throw new NotImplementedException();
}
diff --git a/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs
index 95af9a344..dc363956f 100644
--- a/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs
+++ b/MediaBrowser.Api/HttpHandlers/PluginConfigurationHandler.cs
@@ -17,7 +17,7 @@ namespace MediaBrowser.Api.HttpHandlers
{
return ApiService.IsApiUrlMatch("pluginconfiguration", request);
}
-
+
private BasePlugin _plugin;
private BasePlugin Plugin
{
@@ -39,18 +39,15 @@ namespace MediaBrowser.Api.HttpHandlers
return Task.FromResult(Plugin.Configuration);
}
- public override TimeSpan CacheDuration
+ protected override async Task<ResponseInfo> GetResponseInfo()
{
- get
- {
- return TimeSpan.FromDays(7);
- }
- }
+ var info = await base.GetResponseInfo().ConfigureAwait(false);
- protected override Task<DateTime?> GetLastDateModified()
- {
- return Task.FromResult<DateTime?>(Plugin.ConfigurationDateLastModified);
- }
+ info.DateLastModified = Plugin.ConfigurationDateLastModified;
+ info.CacheDuration = TimeSpan.FromDays(7);
+
+ return info;
+ }
}
}
diff --git a/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs
index 64ba44ec2..48c6761b1 100644
--- a/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs
+++ b/MediaBrowser.Api/HttpHandlers/ServerConfigurationHandler.cs
@@ -16,23 +16,22 @@ namespace MediaBrowser.Api.HttpHandlers
{
return ApiService.IsApiUrlMatch("serverconfiguration", request);
}
-
+
protected override Task<ServerConfiguration> GetObjectToSerialize()
{
return Task.FromResult(Kernel.Instance.Configuration);
}
- public override TimeSpan CacheDuration
+ protected override async Task<ResponseInfo> GetResponseInfo()
{
- get
- {
- return TimeSpan.FromDays(7);
- }
- }
+ var info = await base.GetResponseInfo().ConfigureAwait(false);
- protected override Task<DateTime?> GetLastDateModified()
- {
- return Task.FromResult<DateTime?>(File.GetLastWriteTimeUtc(Kernel.Instance.ApplicationPaths.SystemConfigurationFilePath));
+ info.DateLastModified =
+ File.GetLastWriteTimeUtc(Kernel.Instance.ApplicationPaths.SystemConfigurationFilePath);
+
+ info.CacheDuration = TimeSpan.FromDays(7);
+
+ return info;
}
}
}
diff --git a/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs b/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs
index 90ecae122..378e89067 100644
--- a/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs
+++ b/MediaBrowser.Api/HttpHandlers/WeatherHandler.cs
@@ -16,7 +16,7 @@ namespace MediaBrowser.Api.HttpHandlers
{
return ApiService.IsApiUrlMatch("weather", request);
}
-
+
protected override Task<WeatherInfo> GetObjectToSerialize()
{
// If a specific zip code was requested on the query string, use that. Otherwise use the value from configuration
@@ -31,15 +31,13 @@ namespace MediaBrowser.Api.HttpHandlers
return Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(zipCode);
}
- /// <summary>
- /// Tell the client to cache the weather info for 15 minutes
- /// </summary>
- public override TimeSpan CacheDuration
+ protected override async Task<ResponseInfo> GetResponseInfo()
{
- get
- {
- return TimeSpan.FromMinutes(15);
- }
+ var info = await base.GetResponseInfo().ConfigureAwait(false);
+
+ info.CacheDuration = TimeSpan.FromMinutes(15);
+
+ return info;
}
}
}