// ReSharper disable once CheckNamespace
using Elsa.Http;
namespace Elsa.Extensions;
///
/// Provides extension methods for HTTP headers.
///
public static class HeadersExtensions
{
///
/// Gets the filename from the Content-Disposition header.
///
public static string? GetFilename(this HttpResponseMessage response)
{
var dictionary = response.Headers.ToDictionary(x => x.Key, x => x.Value.ToArray(), StringComparer.OrdinalIgnoreCase);
return dictionary.GetFilename();
}
///
/// Gets the filename from the Content-Disposition header.
///
public static string? GetFilename(this IDictionary headers)
{
if (!headers.TryGetValue("Content-Disposition", out var values))
return null;
var contentDispositionString = string.Join("", values);
var contentDisposition = new System.Net.Mime.ContentDisposition(contentDispositionString);
return contentDisposition.FileName;
}
}