• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Aldaviva / Unfucked / 41054509481

30 Oct 2026 12:18PM UTC coverage: 39.247% (-4.1%) from 43.368%
41054509481

push

github

Aldaviva
HTTP: if message body reader cannot be detected based upon only response Content-Type and target C# type from Send<T>(), then also buffer the first several characters of the response body and pass that to the message body readers to see if any of them can match the prefix, such as <?xml or <!doctype. This feature was already implemented but had a defect where it was unable to rewind the response body stream after buffering the prefix, so the actual deserialization would fail with an unseekable stream. This has been fixed with a wrapper Stream subclass, PartiallyBufferedStream, that delegates reads to either the buffer or the underlying stream depending on the position, so the underlying stream does not need to seek (since HttpClient response body streams can never seek in the first place). This change added a lot more arguments to MessageBodyReader.Read to avoid passing the HttpResponseMessage or HttpContent, which contain the underlying stream that can't seek and would fail to read from the start after content sniffing. Unfucked: added IEnumerable<T>.EmptyToNull to let you null coalesce an empty sequence without enumerating all items. Exposed overloads for deserializer methods in XmlExtensions that take Stream instead of HttpContent, so they can be used with PartiallyBufferedStream.

718 of 2337 branches covered (30.72%)

14 of 50 new or added lines in 10 files covered. (28.0%)

182 existing lines in 16 files now uncovered.

1219 of 3106 relevant lines covered (39.25%)

152.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.71
/HTTP/Serialization/StringBodyReader.cs
1
using System.Net;
2
using System.Net.Http.Headers;
3
using System.Text;
4
using Unfucked.HTTP.Config;
5

6
namespace Unfucked.HTTP.Serialization;
7

8
public sealed class StringBodyReader: MessageBodyReader {
9

UNCOV
10
    public bool CanRead<T>(MediaTypeHeaderValue? contentType, string? bodyPrefix) => typeof(T) == typeof(string);
×
11

12
    public async Task<T> Read<T>(Stream responseBody, HttpStatusCode status, HttpResponseHeaders headers, HttpContentHeaders bodyHeaders, HttpRequestMessage request, IDisposable response,
13
                                 Encoding? responseEncoding, Configurable? clientConfig, CancellationToken cancellationToken) {
14
        using StreamReader streamReader = new(responseBody, responseEncoding ?? Encoding.UTF8, true);
3 ✔
15
        Task<string> readToEndAsync = streamReader
3 ✔
16
#if NET7_0_OR_GREATER
3 ✔
17
            .ReadToEndAsync(cancellationToken);
3 ✔
18
#else
19
            .ReadToEndAsync();
20
#endif
21

22
        return (T) (object) await readToEndAsync.ConfigureAwait(false);
3 ✔
23
    }
3 ✔
24

25
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc