< Summary

Information
Class: Elsa.Http.ContentWriters.RawStringContent
Assembly: Elsa.Http
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/ContentWriters/RawStringContent.cs
Line coverage
100%
Covered lines: 6
Uncovered lines: 0
Coverable lines: 6
Total lines: 29
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetBytes(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Http/ContentWriters/RawStringContent.cs

#LineLine coverage
 1using System.Text;
 2
 3namespace Elsa.Http.ContentWriters;
 4
 5/// <summary>
 6/// HTTP content based on a string that preserves the provided media type as-is (no automatic charset parameter).
 7/// Uses a pre-encoded byte array to guarantee Content-Length == bytes written.
 8/// </summary>
 9public sealed class RawStringContent : ByteArrayContent
 10{
 11    public RawStringContent(string content, Encoding encoding, string mediaType)
 1312        : base(GetBytes(content, encoding))
 13    {
 14        // Set media type exactly as provided, without charset parameter.
 1315        Headers.ContentType = new(mediaType);
 1316    }
 17
 18    private static byte[] GetBytes(string content, Encoding encoding)
 19    {
 1320        ArgumentNullException.ThrowIfNull(content);
 1321        ArgumentNullException.ThrowIfNull(encoding);
 22
 23        // Ensure we don't include a BOM/preamble. Most Encoding instances can expose a preamble.
 24        // If encoding has a preamble, we must not include it, so use GetBytes directly (preamble is only returned by Ge
 25        // For safety, if the encoding instance is a BOM-producing variant (e.g., new UTF8Encoding(true)),
 26        // GetBytes does not include the BOM; only GetPreamble() would. So this is safe.
 1327        return encoding.GetBytes(content);
 28    }
 29}