• 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

2.86
/HTTP/Serialization/StreamBodyReader.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 StreamBodyReader: AbstractMessageBodyReader {
8

9
    public override bool CanRead<T>(MediaTypeHeaderValue? contentType) => typeof(T) == typeof(Stream);
4 ✔
10

11
    public override async Task<T> Read<T>(HttpResponseMessage response, Encoding? responseEncoding, Configurable? clientConfig, CancellationToken cancellationToken) =>
NEW
12
        (T) (object) new ResponseDisposingStream(await GetBodyStream(response, cancellationToken), response);
×
13

14
    private sealed class ResponseDisposingStream(Stream actualStream, IDisposable alsoDispose): Stream {
×
15

16
        public override bool CanRead => actualStream.CanRead;
×
17
        public override bool CanSeek => actualStream.CanSeek;
×
18
        public override bool CanWrite => actualStream.CanWrite;
×
19
        public override long Length => actualStream.Length;
×
20
        public override bool CanTimeout => actualStream.CanTimeout;
×
21
        public override long Position {
22
            get => actualStream.Position;
×
23
            set => actualStream.Position = value;
×
24
        }
25
        public override int ReadTimeout {
26
            get => actualStream.ReadTimeout;
×
27
            set => actualStream.ReadTimeout = value;
×
28
        }
29
        public override int WriteTimeout {
30
            get => actualStream.WriteTimeout;
×
31
            set => actualStream.WriteTimeout = value;
×
32
        }
33

34
        public override void Flush() => actualStream.Flush();
×
35

36
        public override int Read(byte[] buffer, int offset, int count) => actualStream.Read(buffer, offset, count);
×
37

38
        public override long Seek(long offset, SeekOrigin origin) => actualStream.Seek(offset, origin);
×
39

40
        public override void SetLength(long value) => actualStream.SetLength(value);
×
41

42
        public override void Write(byte[] buffer, int offset, int count) => actualStream.Write(buffer, offset, count);
×
43

44
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => actualStream.BeginRead(buffer, offset, count, callback, state);
×
45

46
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback? callback, object? state) => actualStream.BeginWrite(buffer, offset, count, callback, state);
×
47

48
        public override void Close() => actualStream.Close();
×
49

50
        public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) => actualStream.CopyToAsync(destination, bufferSize, cancellationToken);
×
51

52
        public override int EndRead(IAsyncResult asyncResult) => actualStream.EndRead(asyncResult);
×
53

54
        public override void EndWrite(IAsyncResult asyncResult) => actualStream.EndWrite(asyncResult);
×
55

56
        public override Task FlushAsync(CancellationToken cancellationToken) => actualStream.FlushAsync(cancellationToken);
×
57

58
        public override Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => actualStream.ReadAsync(buffer, offset, count, cancellationToken);
×
59

60
        public override int ReadByte() => actualStream.ReadByte();
×
61

62
        public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => actualStream.WriteAsync(buffer, offset, count, cancellationToken);
×
63

64
        public override void WriteByte(byte value) => actualStream.WriteByte(value);
×
65

66
        protected override void Dispose(bool disposing) {
67
            if (disposing) {
×
68
                actualStream.Dispose();
×
69
                alsoDispose.Dispose();
×
70
            }
71
            base.Dispose(disposing);
×
72
        }
×
73

74
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_0_OR_GREATER
75
        public override void CopyTo(Stream destination, int bufferSize) => actualStream.CopyTo(destination, bufferSize);
76
#endif
77

78
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP2_1_OR_GREATER
79
        public override int Read(Span<byte> buffer) => actualStream.Read(buffer);
80

81
        public override ValueTask<int> ReadAsync(Memory<byte> buffer, CancellationToken cancellationToken = default) => actualStream.ReadAsync(buffer, cancellationToken);
82

83
        public override void Write(ReadOnlySpan<byte> buffer) => actualStream.Write(buffer);
84

85
        public override ValueTask WriteAsync(ReadOnlyMemory<byte> buffer, CancellationToken cancellationToken = default) => actualStream.WriteAsync(buffer, cancellationToken);
86
#endif
87

88
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_0_OR_GREATER
89
        public override async ValueTask DisposeAsync() {
90
            await actualStream.DisposeAsync().ConfigureAwait(false);
91
            if (alsoDispose is IAsyncDisposable alsoDisposeAsyncDisposable) {
×
92
                await alsoDisposeAsyncDisposable.DisposeAsync().ConfigureAwait(false);
93
            } else {
94
                alsoDispose.Dispose();
95
            }
96
            await base.DisposeAsync().ConfigureAwait(false);
97
        }
98
#endif
99

100
    }
101

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