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

Aldaviva / Unfucked / 41068530179

30 Oct 2026 02:03PM UTC coverage: 46.159% (+0.1%) from 46.063%
41068530179

push

github

Aldaviva
HTTP: revert making all MessageBodyReaders take lots of arguments and not have access to the HttpResponseMessage or HttpContent just so they would always be forced to use the PartiallyBufferedStream, because most readers don't sniff body prefixes (only XML and JSON object mapping readers do), and it prevents the rest of them from using the optimized methods on HttpContent to read the body as a byte array or string. Solved by making a richer type hierarchy where the prefix sniffing lives in an abstract superclass that implements MessageBodyReader, and WebTarget is aware of it and can call it only when it's actually trying to detect prefixes. This has the added benefit that non-prefix-aware readers are skipped if they've already mismatched and won't be re-asked if they can handle the response when in the second phase prefix sniffing pass of deserialization.

838 of 2337 branches covered (35.86%)

44 of 67 new or added lines in 9 files covered. (65.67%)

2 existing lines in 2 files now uncovered.

1454 of 3150 relevant lines covered (46.16%)

151.49 hits per line

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

81.82
/HTTP/Serialization/ByteArrayBodyReader.cs
1
using System.Net.Http.Headers;
2
using System.Text;
3
using Unfucked.HTTP.Config;
4

5
namespace Unfucked.HTTP.Serialization;
6

7
public sealed class ByteArrayBodyReader: MessageBodyReader {
8

9
    public bool CanRead<T>(MediaTypeHeaderValue? contentType) => typeof(T) == typeof(byte[]);
4 ✔
10

11
    public async Task<T> Read<T>(HttpResponseMessage response, Encoding? responseEncoding, Configurable? clientConfig, CancellationToken cancellationToken) =>
12
        (T) (object) await ReadByteArray(response, cancellationToken).ConfigureAwait(false);
1 ✔
13

14
    public sealed class MemoryBodyReader: MessageBodyReader {
15

16
        public bool CanRead<T>(MediaTypeHeaderValue? contentType) => typeof(T) == typeof(Memory<byte>);
4 ✔
17

18
        public async Task<T> Read<T>(HttpResponseMessage response, Encoding? responseEncoding, Configurable? clientConfig, CancellationToken cancellationToken) =>
NEW
19
            (T) (object) (await ReadByteArray(response, cancellationToken).ConfigureAwait(false)).AsMemory();
×
20

21
    }
22

23
    public sealed class ReadOnlyMemoryBodyReader: MessageBodyReader {
24

25
        public bool CanRead<T>(MediaTypeHeaderValue? contentType) => typeof(T) == typeof(ReadOnlyMemory<byte>);
4 ✔
26

27
        public async Task<T> Read<T>(HttpResponseMessage response, Encoding? responseEncoding, Configurable? clientConfig, CancellationToken cancellationToken) =>
NEW
28
            (T) (object) new ReadOnlyMemory<byte>(await ReadByteArray(response, cancellationToken).ConfigureAwait(false));
×
29

30
    }
31

32
    private static async Task<byte[]> ReadByteArray(HttpResponseMessage response, CancellationToken cancellationToken) {
33
        Task<byte[]> bodyTask =
1 ✔
34
#if NET5_0_OR_GREATER
1 ✔
35
            response.Content.ReadAsByteArrayAsync(cancellationToken);
1 ✔
36
#else
37
            response.Content.ReadAsByteArrayAsync();
38
#endif
39

40
        return await bodyTask.ConfigureAwait(false);
1 ✔
41
    }
1 ✔
42

43
}
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