aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/Library/LibraryService.cs
diff options
context:
space:
mode:
authorJean-Samuel Aubry-Guzzi <DrPandemic@users.noreply.github.com>2019-04-23 17:31:38 -0400
committerDrPandemic <bipbip500@gmail.com>2019-05-07 19:43:04 -0400
commit12721eb7dd20d6a24c8873f9c0fb36f621116650 (patch)
treef40e28a36196e1537e178e829dc0bb6a5923d805 /MediaBrowser.Api/Library/LibraryService.cs
parente8196fed7cdc43f83f666af477652a90f41b5961 (diff)
Fix non-ascii filename downloads
Follow https://tools.ietf.org/html/rfc5987#section-3.2.2 to encode non-ascii filenames in HTTP Content-Disposition header.
Diffstat (limited to 'MediaBrowser.Api/Library/LibraryService.cs')
-rw-r--r--MediaBrowser.Api/Library/LibraryService.cs13
1 files changed, 12 insertions, 1 deletions
diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs
index 8eefbdf2c..9f8da9c16 100644
--- a/MediaBrowser.Api/Library/LibraryService.cs
+++ b/MediaBrowser.Api/Library/LibraryService.cs
@@ -2,6 +2,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Net;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Api.Movies;
@@ -828,7 +830,16 @@ namespace MediaBrowser.Api.Library
var filename = (Path.GetFileName(path) ?? string.Empty).Replace("\"", string.Empty);
if (!string.IsNullOrWhiteSpace(filename))
{
- headers[HeaderNames.ContentDisposition] = "attachment; filename=\"" + filename + "\"";
+ // Kestrel doesn't support non-ASCII characters in headers
+ if (Regex.IsMatch(filename, "[^[:ascii:]]"))
+ {
+ // Manually encoding non-ASCII characters, following https://tools.ietf.org/html/rfc5987#section-3.2.2
+ headers[HeaderNames.ContentDisposition] = "attachment; filename*=UTF-8''" + WebUtility.UrlEncode(filename);
+ }
+ else
+ {
+ headers[HeaderNames.ContentDisposition] = "attachment; filename=\"" + filename + "\"";
+ }
}
return ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions