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

Aldaviva / Unfucked / 24047187514

06 Apr 2026 07:22PM UTC coverage: 43.559% (-1.7%) from 45.265%
24047187514

push

github

Aldaviva
Make lambdas static where possible for better performance. Use concrete types instead of interfaces where possible to avoid virtual calls, also for perceived performance. Add more extensions to easily create ConcurrentDictionaries with atomic mutable values. Make mutable value holders in ConcurrentDictionary not equatable except for reference equality to avoid instances getting lost in the dictionary when the value and therefore hashcode changes. Added overloads to ConcurrentDictionary addition-aware upserting to take a valueFactory argument, to allow callers to not have to create a closure for their valueFactory if they already had a value they wanted to pass to it. Removed usage of array pool when converting special URL characters to their URL-encoded form, because the arrays are short enough (4 bytes) that it's faster to allocate and collect with GC than to borrow and return to a pool.

645 of 1560 branches covered (41.35%)

65 of 148 new or added lines in 22 files covered. (43.92%)

86 existing lines in 7 files now uncovered.

1143 of 2624 relevant lines covered (43.56%)

177.96 hits per line

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

0.0
/HTTP/HttpRequest.cs
1
using Unfucked.HTTP.Config;
2

3
namespace Unfucked.HTTP;
4

5
public readonly record struct HttpRequest(HttpMethod Verb, Uri Uri, IEnumerable<KeyValuePair<string, string>> Headers, HttpContent? Body, IClientConfig? ClientConfig) {
×
6

7
    public static async Task<HttpRequest> Copy(HttpRequestMessage original) {
NEW
8
        IEnumerable<KeyValuePair<string, string>> replayedHeaders = original.Headers.SelectMany(static header => header.Value.Select(val => new KeyValuePair<string, string>(header.Key, val)));
×
9

10
        HttpContent? replayedRequestBody = null;
×
11
        if (original.Content is {} originalBody) {
×
12
            MemoryStream replayedRequestBodyStream = new();
×
13
            // CopyToAsync may fail if the original stream isn't seekable, in which case we should buffer all request bodies before their original request is sent
14
            await originalBody.CopyToAsync(replayedRequestBodyStream).ConfigureAwait(false);
×
15
            replayedRequestBody = new StreamContent(replayedRequestBodyStream);
×
16
            foreach (KeyValuePair<string, IEnumerable<string>> originalRequestBodyHeader in originalBody.Headers) {
×
17
                replayedRequestBody.Headers.Add(originalRequestBodyHeader.Key, originalRequestBodyHeader.Value);
×
18
            }
19
        }
×
20

21
        return new HttpRequest(original.Method, original.RequestUri!, replayedHeaders, replayedRequestBody, null);
×
22
    }
×
23

24
    /*
25
     * These crappy methods are only used for testing, so some are synchronous and inefficient
26
     */
27
    public bool Equals(HttpRequest other) =>
28
        Verb.Equals(other.Verb) &&
×
29
        Uri.Equals(other.Uri) &&
×
30
        Headers.Count() == other.Headers.Count() &&
×
31
        new HashSet<KeyValuePair<string, string>>(Headers, HeaderNameEqualityComparer.Instance).SetEquals(new HashSet<KeyValuePair<string, string>>(other.Headers,
×
32
            HeaderNameEqualityComparer.Instance)) &&
×
33
        ((Body is null && other.Body is null) ||
×
34
            (Body is not null && other.Body is not null && (SerializeBodySync()?.Equals(other.SerializeBodySync(), StringComparison.InvariantCulture) ?? true)));
×
35

36
    public override int GetHashCode() {
37
        unchecked {
38
            int hashCode = Verb.GetHashCode();
×
39
            hashCode = (hashCode * 397) ^ Uri.GetHashCode();
×
40
            hashCode = (hashCode * 397) ^ Headers.GetHashCode();
×
41
            hashCode = (hashCode * 397) ^ (Body != null ? Body.GetHashCode() : 0);
×
42
            return hashCode;
×
43
        }
44
    }
45

46
    public override string ToString() =>
47
        $"""
×
48
        {Verb} {Uri}
×
NEW
49
        {Headers.Select(static pair => $"{pair.Key}: {pair.Value}").Join('\n')}
×
50

×
51
        {SerializeBodySync()}
×
52
        """;
×
53

54
    private string? SerializeBodySync() => Body?.ReadAsStringAsync().GetAwaiter().GetResult();
×
55

56
    private sealed class HeaderNameEqualityComparer: IEqualityComparer<KeyValuePair<string, string>> {
57

58
        public static readonly HeaderNameEqualityComparer Instance = new();
×
59

NEW
60
        public bool Equals(KeyValuePair<string, string> x, KeyValuePair<string, string> y) => string.Equals(x.Key, y.Key, StringComparison.InvariantCultureIgnoreCase);
×
61

NEW
62
        public int GetHashCode(KeyValuePair<string, string> obj) => StringComparer.InvariantCultureIgnoreCase.GetHashCode((object) obj.Key);
×
63

64
    }
65

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

© 2026 Coveralls, Inc