< Summary

Information
Class: Elsa.Extensions.HeadersExtensions
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Extensions/HeadersExtensions.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 7
Coverable lines: 7
Total lines: 32
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetFilename(...)100%210%
GetFilename(...)0%620%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/Extensions/HeadersExtensions.cs

#LineLine coverage
 1// ReSharper disable once CheckNamespace
 2using Elsa.Http;
 3
 4namespace Elsa.Extensions;
 5
 6/// <summary>
 7/// Provides extension methods for HTTP headers.
 8/// </summary>
 9public 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    {
 016        var dictionary = response.Headers.ToDictionary(x => x.Key, x => x.Value.ToArray(), StringComparer.OrdinalIgnoreC
 017        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    {
 025        if (!headers.TryGetValue("Content-Disposition", out var values))
 026            return null;
 27
 028        var contentDispositionString = string.Join("", values);
 029        var contentDisposition = new System.Net.Mime.ContentDisposition(contentDispositionString);
 030        return contentDisposition.FileName;
 31    }
 32}