diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-07-23 02:12:16 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-23 02:12:16 -0400 |
| commit | 5ec9d4e9fe4b3e5109ca1abf6c1ffdb87fd2d4dd (patch) | |
| tree | e49cc827583b6dffeabb142af5fae889b1a09581 /Emby.Server.Implementations/HttpServer | |
| parent | e99bc61d53f393dc475e265e3b5bc8c19b186594 (diff) | |
| parent | 0d1b5ad733e6f1bbf6d730e723969495dda99016 (diff) | |
Merge pull request #2767 from MediaBrowser/beta
Beta
Diffstat (limited to 'Emby.Server.Implementations/HttpServer')
| -rw-r--r-- | Emby.Server.Implementations/HttpServer/HttpListenerHost.cs | 28 | ||||
| -rw-r--r-- | Emby.Server.Implementations/HttpServer/HttpResultFactory.cs | 9 |
2 files changed, 36 insertions, 1 deletions
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 28c23b766..05f78eba9 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -104,6 +104,7 @@ namespace Emby.Server.Implementations.HttpServer readonly Dictionary<Type, int> _mapExceptionToStatusCode = new Dictionary<Type, int> { {typeof (ResourceNotFoundException), 404}, + {typeof (RemoteServiceUnavailableException), 502}, {typeof (FileNotFoundException), 404}, //{typeof (DirectoryNotFoundException), 404}, {typeof (SecurityException), 401}, @@ -268,6 +269,29 @@ namespace Emby.Server.Implementations.HttpServer } } + private Exception GetActualException(Exception ex) + { + var agg = ex as AggregateException; + if (agg != null) + { + var inner = agg.InnerException; + if (inner != null) + { + return GetActualException(inner); + } + else + { + var inners = agg.InnerExceptions; + if (inners != null && inners.Count > 0) + { + return GetActualException(inners[0]); + } + } + } + + return ex; + } + private int GetStatusCode(Exception ex) { if (ex is ArgumentException) @@ -280,7 +304,7 @@ namespace Emby.Server.Implementations.HttpServer int statusCode; if (!_mapExceptionToStatusCode.TryGetValue(exceptionType, out statusCode)) { - if (string.Equals(exceptionType.Name, "DirectoryNotFoundException", StringComparison.OrdinalIgnoreCase)) + if (ex is DirectoryNotFoundException) { statusCode = 404; } @@ -297,6 +321,8 @@ namespace Emby.Server.Implementations.HttpServer { try { + ex = GetActualException(ex); + if (logException) { _logger.ErrorException("Error processing request", ex); diff --git a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs index 6c37d5f7a..396bd8e88 100644 --- a/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/Emby.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -438,6 +438,15 @@ namespace Emby.Server.Implementations.HttpServer options.CacheKey = cacheKey.GetMD5(); options.ContentFactory = () => Task.FromResult(GetFileStream(path, fileShare)); + options.ResponseHeaders = options.ResponseHeaders ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); + + // Quotes are valid in linux. They'll possibly cause issues here + var filename = (Path.GetFileName(path) ?? string.Empty).Replace("\"", string.Empty); + if (!string.IsNullOrWhiteSpace(filename)) + { + options.ResponseHeaders["Content-Disposition"] = "inline; filename=\"" + filename + "\""; + } + return GetStaticResult(requestContext, options); } |
