Skip to content

Commit

Permalink
#590 drop WithClient (client.Request should be used instead)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Jun 10, 2022
1 parent 5fd95f0 commit 1b7aec6
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 64 deletions.
20 changes: 3 additions & 17 deletions Test/Flurl.Test/Http/SettingsExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,6 @@ public void WithUrl_shares_client_but_not_Url() {
CollectionAssert.AllItemsAreUnique(urls);
}

[Test]
public void WithClient_shares_client_but_not_Url() {
var cli = new FlurlClient().WithHeader("myheader", "123");
var req1 = "http://www.api.com/for-req1".WithClient(cli);
var req2 = "http://www.api.com/for-req2".WithClient(cli);
var req3 = "http://www.api.com/for-req3".WithClient(cli);

CollectionAssert.AreEquivalent(req1.Headers, req2.Headers);
CollectionAssert.AreEquivalent(req1.Headers, req3.Headers);
var urls = new[] { req1, req2, req3 }.Select(c => c.Url.ToString());
CollectionAssert.AllItemsAreUnique(urls);
}

[Test]
public void can_use_uri_with_WithUrl() {
var uri = new System.Uri("http://www.mysite.com/foo?x=1");
Expand All @@ -211,10 +198,9 @@ public void can_override_settings_fluently() {
using (var test = new HttpTest()) {
var cli = new FlurlClient().Configure(s => s.AllowedHttpStatusRange = "*");
test.RespondWith("epic fail", 500);
Assert.ThrowsAsync<FlurlHttpException>(async () => await "http://www.api.com"
.ConfigureRequest(c => c.AllowedHttpStatusRange = "2xx")
.WithClient(cli) // client-level settings shouldn't win
.GetAsync());
var req = "http://www.api.com".ConfigureRequest(c => c.AllowedHttpStatusRange = "2xx");
req.Client = cli; // client-level settings shouldn't win
Assert.ThrowsAsync<FlurlHttpException>(async () => await req.GetAsync());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Test/Flurl.Test/Http/SettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void settings_propagate_correctly() {
var client2 = new FlurlClient();
client2.Settings.Redirects.Enabled = false;

req.WithClient(client2);
req.Client = client2;
Assert.IsFalse(req.Settings.Redirects.Enabled, "request should inherit client settings when not set at request level");
Assert.AreEqual("4xx", req.Settings.AllowedHttpStatusRange, "request should inherit global settings when not set at request or client level");
Assert.AreEqual(123, req.Settings.Redirects.MaxAutoRedirects, "request should inherit global settings when not set at request or client level");
Expand Down
3 changes: 0 additions & 3 deletions src/Flurl.CodeGen/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ public static IEnumerable<ExtensionMethod> GetRequestReturningExtensions(MethodA
yield return Create("AllowAnyHttpStatus", "Creates a new FlurlRequest and configures it to allow any returned HTTP status without throwing a FlurlHttpException.");
yield return Create("WithAutoRedirect", "Creates a new FlurlRequest and configures whether redirects are automatically followed.")
.AddArg("enabled", "bool", "true if Flurl should automatically send a new request to the redirect URL, false if it should not.");

yield return Create("WithClient", "Creates a new FlurlRequest and configures it to use the given IFlurlClient.")
.AddArg("client", "IFlurlClient", "The IFlurlClient to use to send the request.");
}

/// <summary>
Expand Down
3 changes: 1 addition & 2 deletions src/Flurl.Http/FlurlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ private bool ConnectionLeaseExpired() {
public HttpMessageHandler HttpMessageHandler => HttpTest.Current?.HttpMessageHandler ?? _httpMessageHandler?.Value;

/// <inheritdoc />
public IFlurlRequest Request(params object[] urlSegments) =>
new FlurlRequest(BaseUrl, urlSegments).WithClient(this);
public IFlurlRequest Request(params object[] urlSegments) => new FlurlRequest(BaseUrl, urlSegments) { Client = this };

FlurlHttpSettings IHttpSettingsContainer.Settings {
get => Settings;
Expand Down
30 changes: 0 additions & 30 deletions src/Flurl.Http/GeneratedExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,16 +711,6 @@ public static IFlurlRequest WithAutoRedirect(this Url url, bool enabled) {
return new FlurlRequest(url).WithAutoRedirect(enabled);
}

/// <summary>
/// Creates a new FlurlRequest and configures it to use the given IFlurlClient.
/// </summary>
/// <param name="url">This Flurl.Url.</param>
/// <param name="client">The IFlurlClient to use to send the request.</param>
/// <returns>A new IFlurlRequest.</returns>
public static IFlurlRequest WithClient(this Url url, IFlurlClient client) {
return new FlurlRequest(url).WithClient(client);
}

/// <summary>
/// Creates a FlurlRequest and sends an asynchronous request.
/// </summary>
Expand Down Expand Up @@ -1160,16 +1150,6 @@ public static IFlurlRequest WithAutoRedirect(this string url, bool enabled) {
return new FlurlRequest(url).WithAutoRedirect(enabled);
}

/// <summary>
/// Creates a new FlurlRequest and configures it to use the given IFlurlClient.
/// </summary>
/// <param name="url">This URL.</param>
/// <param name="client">The IFlurlClient to use to send the request.</param>
/// <returns>A new IFlurlRequest.</returns>
public static IFlurlRequest WithClient(this string url, IFlurlClient client) {
return new FlurlRequest(url).WithClient(client);
}

/// <summary>
/// Creates a FlurlRequest and sends an asynchronous request.
/// </summary>
Expand Down Expand Up @@ -1609,15 +1589,5 @@ public static IFlurlRequest WithAutoRedirect(this Uri uri, bool enabled) {
return new FlurlRequest(uri).WithAutoRedirect(enabled);
}

/// <summary>
/// Creates a new FlurlRequest and configures it to use the given IFlurlClient.
/// </summary>
/// <param name="uri">This System.Uri.</param>
/// <param name="client">The IFlurlClient to use to send the request.</param>
/// <returns>A new IFlurlRequest.</returns>
public static IFlurlRequest WithClient(this Uri uri, IFlurlClient client) {
return new FlurlRequest(uri).WithClient(client);
}

}
}
11 changes: 0 additions & 11 deletions src/Flurl.Http/SettingsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ public static IFlurlRequest ConfigureRequest(this IFlurlRequest request, Action<
return request;
}

/// <summary>
/// Fluently specify the IFlurlClient to use with this IFlurlRequest.
/// </summary>
/// <param name="request">The IFlurlRequest.</param>
/// <param name="client">The IFlurlClient to use when sending the request.</param>
/// <returns>A new IFlurlRequest to use in calling the Url</returns>
public static IFlurlRequest WithClient(this IFlurlRequest request, IFlurlClient client) {
request.Client = client;
return request;
}

/// <summary>
/// Sets the timeout for this IFlurlRequest or all requests made with this IFlurlClient.
/// </summary>
Expand Down

0 comments on commit 1b7aec6

Please sign in to comment.