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

Aldaviva / Unfucked / 19128584806

06 Nov 2025 07:47AM UTC coverage: 0.396% (-39.5%) from 39.923%
19128584806

push

github

Aldaviva
DateTime: added IsBefore and IsAfter for ZonedDateTime, not just OffsetDateTime. DI: Allow super registration for keyed services; fixed super registration of a hosted service causing an infinite recursion during injection. STUN: updated fallback server list, most of which have gone offline (including Google, confusingly); made HttpClient optional.

2 of 1605 branches covered (0.12%)

0 of 55 new or added lines in 2 files covered. (0.0%)

945 existing lines in 35 files now uncovered.

9 of 2272 relevant lines covered (0.4%)

0.04 hits per line

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

0.0
/HTTP/Extensions.cs
1
using System.Diagnostics.Contracts;
2
using Unfucked.HTTP.Config;
3
using Unfucked.HTTP.Exceptions;
4
using Unfucked.HTTP.Filters;
5
using Unfucked.HTTP.Serialization;
6

7
namespace Unfucked.HTTP;
8

9
public static class Extensions {
10

11
    #region Targeting
12

13
    /// <summary>
14
    /// Begin building an HTTP request for a given URL
15
    /// </summary>
16
    /// <param name="httpClient">HTTP client</param>
17
    /// <param name="uri">URL to send request to</param>
18
    /// <returns>Web target, on which you can call builder methods to set up the request, ending in one of the verb methods like <c>Get</c> to send the built request</returns>
19
    [Pure]
20
    public static IWebTarget Target(this HttpClient httpClient, Uri uri) => new WebTarget(HttpClientWrapper.Wrap(httpClient), uri);
×
21

22
    /// <inheritdoc cref="Target(System.Net.Http.HttpClient,System.Uri)" />
23
    [Pure]
24
    public static IWebTarget Target<H>(this H httpClient, Uri uri) where H: IHttpClient => new WebTarget(httpClient, uri);
×
25

26
    /// <inheritdoc cref="Target(System.Net.Http.HttpClient,System.Uri)" />
27
    [Pure]
28
    public static IWebTarget Target(this HttpClient httpClient, string uri) => new WebTarget(HttpClientWrapper.Wrap(httpClient), uri);
×
29

30
    /// <inheritdoc cref="Target(System.Net.Http.HttpClient,string)" />
31
    [Pure]
UNCOV
32
    public static IWebTarget Target<H>(this H httpClient, string uri) where H: IHttpClient => new WebTarget(httpClient, uri);
×
33

34
    /// <summary>
35
    /// Begin building an HTTP request for a given URL
36
    /// </summary>
37
    /// <param name="httpClient">HTTP client</param>
38
    /// <param name="urlBuilder">URL to send request to</param>
39
    /// <returns>Web target, on which you can call builder methods to set up the request, ending in one of the verb methods like <c>Get</c> to send the built request</returns>
40
    [Pure]
41
    public static IWebTarget Target(this HttpClient httpClient, UrlBuilder urlBuilder) => new WebTarget(HttpClientWrapper.Wrap(httpClient), urlBuilder);
×
42

43
    /// <inheritdoc cref="Target(System.Net.Http.HttpClient,UrlBuilder)" />
44
    [Pure]
45
    public static IWebTarget Target<H>(this H httpClient, UrlBuilder urlBuilder) where H: IHttpClient => new WebTarget(httpClient, urlBuilder);
×
46

47
    /// <summary>
48
    /// Begin building an HTTP request for a given URL
49
    /// </summary>
50
    /// <param name="httpClient">HTTP client</param>
51
    /// <param name="uriBuilder">URL to send request to</param>
52
    /// <returns>Web target, on which you can call builder methods to set up the request, ending in one of the verb methods like <c>Get</c> to send the built request</returns>
53
    [Pure]
54
    public static IWebTarget Target(this HttpClient httpClient, UriBuilder uriBuilder) => new WebTarget(HttpClientWrapper.Wrap(httpClient), uriBuilder);
×
55

56
    /// <inheritdoc cref="Target(System.Net.Http.HttpClient,UriBuilder)" />
57
    [Pure]
58
    public static IWebTarget Target<H>(this H httpClient, UriBuilder uriBuilder) where H: IHttpClient => new WebTarget(httpClient, uriBuilder);
×
59

60
    #endregion
61

62
    #region Configuration
63

64
    /// <inheritdoc cref="Register(IHttpClient,ClientRequestFilter,int)" />
65
    public static H Register<H>(this H httpClient, ClientRequestFilter filter, int position = ClientConfig.LAST_FILTER_POSITION) where H: HttpClient {
66
        _ = UnfuckedHttpHandler.FindHandler(httpClient)?.Register(filter, position) ?? throw WebTarget.ConfigUnavailable;
×
67
        return httpClient;
×
68
    }
69

70
    /// <summary>Register a client request filter to run before requests are sent for this client</summary>
71
    /// <returns>This mutated instance</returns>
72
    /// <exception cref="InvalidOperationException">the <paramref name="httpClient"/> does not have a usable configuration because of how it was constructed</exception>
73
    public static IHttpClient Register(this IHttpClient httpClient, ClientRequestFilter filter, int position = ClientConfig.LAST_FILTER_POSITION) {
74
        _ = httpClient.Handler?.Register(filter, position) ?? throw WebTarget.ConfigUnavailable;
×
75
        return httpClient;
×
76
    }
77

78
    /// <inheritdoc cref="Register(IHttpClient,ClientResponseFilter,int)" />
79
    public static H Register<H>(this H httpClient, ClientResponseFilter filter, int position = ClientConfig.LAST_FILTER_POSITION) where H: HttpClient {
80
        _ = UnfuckedHttpHandler.FindHandler(httpClient)?.Register(filter, position) ?? throw WebTarget.ConfigUnavailable;
×
81
        return httpClient;
×
82
    }
83

84
    /// <summary>Register a client response filter to run after requests are received for this client</summary>
85
    /// <returns>This mutated instance</returns>
86
    /// <exception cref="InvalidOperationException">the <paramref name="httpClient"/> does not have a usable configuration because of how it was constructed</exception>
87
    public static IHttpClient Register(this IHttpClient httpClient, ClientResponseFilter filter, int position = ClientConfig.LAST_FILTER_POSITION) {
88
        _ = httpClient.Handler?.Register(filter, position) ?? throw WebTarget.ConfigUnavailable;
×
89
        return httpClient;
×
90
    }
91

92
    /// <inheritdoc cref="Register(IHttpClient,MessageBodyReader)" />
93
    public static H Register<H>(this H httpClient, MessageBodyReader reader) where H: HttpClient {
94
        _ = UnfuckedHttpHandler.FindHandler(httpClient)?.Register(reader) ?? throw WebTarget.ConfigUnavailable;
×
95
        return httpClient;
×
96
    }
97

98
    /// <summary>Register a message body reader to deserialize responses for this client</summary>
99
    /// <returns>This mutated instance</returns>
100
    /// <exception cref="InvalidOperationException">the <paramref name="httpClient"/> does not have a usable configuration because of how it was constructed</exception>
101
    public static IHttpClient Register(this IHttpClient httpClient, MessageBodyReader reader) {
102
        _ = httpClient.Handler?.Register(reader) ?? throw WebTarget.ConfigUnavailable;
×
103
        return httpClient;
×
104
    }
105

106
    /// <inheritdoc cref="Property{T}(IHttpClient,PropertyKey{T},T)" />
107
    public static H Property<H, T>(this H httpClient, PropertyKey<T> key, T? newValue) where H: HttpClient where T: notnull {
108
        _ = UnfuckedHttpHandler.FindHandler(httpClient)?.Property(key, newValue) ?? throw WebTarget.ConfigUnavailable;
×
109
        return httpClient;
×
110
    }
111

112
    /// <summary>Set a property on the client.</summary>
113
    /// <exception cref="InvalidOperationException">the <paramref name="httpClient"/> does not have a usable configuration because of how it was constructed</exception>
114
    public static IHttpClient Property<T>(this IHttpClient httpClient, PropertyKey<T> key, T? newValue) where T: notnull {
115
        _ = httpClient.Handler?.Property(key, newValue) ?? throw WebTarget.ConfigUnavailable;
×
116
        return httpClient;
×
117
    }
118

119
    /// <inheritdoc cref="Property{T}(IHttpClient,PropertyKey{T},out T)" />
120
    [Pure]
121
    public static bool Property<H, T>(this H httpClient, PropertyKey<T> key, out T? existingValue) where H: HttpClient where T: notnull =>
122
        UnfuckedHttpHandler.FindHandler(httpClient) is { } handler ? handler.Property(key, out existingValue) : throw WebTarget.ConfigUnavailable;
×
123

124
    /// <summary>Get a property from the client.</summary>
125
    /// <exception cref="InvalidOperationException">the <paramref name="httpClient"/> does not have a usable configuration because of how it was constructed</exception>
126
    [Pure]
127
    public static bool Property<T>(this IHttpClient httpClient, PropertyKey<T> key, out T? existingValue) where T: notnull =>
128
        httpClient.Handler is { } handler ? handler.Property(key, out existingValue) : throw WebTarget.ConfigUnavailable;
×
129

130
    #endregion
131

132
    /// <summary>
133
    /// <para>Immediately throw a <see cref="WebApplicationException"/> if this HTTP response did not have a successful status code.</para>
134
    /// <para>This is a per-request, imperative alternative to leaving <see cref="PropertyKey.ThrowOnUnsuccessfulStatusCode"/> set to <c>true</c> on your <see cref="IClientConfig"/>, <see cref="IUnfuckedHttpHandler"/>, <see cref="HttpClient"/>, or <see cref="IWebTarget"/>, which applies to all requests sent. Since that property defaults to <c>true</c>, calling this method is only useful if you manually changed that property to <c>false</c>.</para>
135
    /// </summary>
136
    /// <param name="response">completed HTTP response</param>
137
    /// <param name="cancellationToken">cancel reading response body</param>
138
    /// <returns>a Task that resolves with no return value if if the response status code is successful</returns>
139
    /// <exception cref="WebApplicationException">the response status code was not successful</exception>
140
    public static Task ThrowIfUnsuccessful(this HttpResponseMessage response, CancellationToken cancellationToken = default) => WebTarget.ThrowIfUnsuccessful(response, cancellationToken);
×
141

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