| | | 1 | | // ReSharper disable once CheckNamespace |
| | | 2 | | using Elsa.Http; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Extensions; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Provides extension methods for HTTP headers. |
| | | 8 | | /// </summary> |
| | | 9 | | public static class HeadersExtensions |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Gets the filename from the Content-Disposition header. |
| | | 13 | | /// </summary> |
| | | 14 | | public static string? GetFilename(this HttpResponseMessage response) |
| | | 15 | | { |
| | 0 | 16 | | var dictionary = response.Headers.ToDictionary(x => x.Key, x => x.Value.ToArray(), StringComparer.OrdinalIgnoreC |
| | 0 | 17 | | return dictionary.GetFilename(); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// Gets the filename from the Content-Disposition header. |
| | | 22 | | /// </summary> |
| | | 23 | | public static string? GetFilename(this IDictionary<string, string[]> headers) |
| | | 24 | | { |
| | 0 | 25 | | if (!headers.TryGetValue("Content-Disposition", out var values)) |
| | 0 | 26 | | return null; |
| | | 27 | | |
| | 0 | 28 | | var contentDispositionString = string.Join("", values); |
| | 0 | 29 | | var contentDisposition = new System.Net.Mime.ContentDisposition(contentDispositionString); |
| | 0 | 30 | | return contentDisposition.FileName; |
| | | 31 | | } |
| | | 32 | | } |