From 1b7aec690bcbad0521a2e324bc9d33923721bab9 Mon Sep 17 00:00:00 2001 From: Todd Date: Fri, 10 Jun 2022 13:16:02 -0500 Subject: [PATCH] #590 drop WithClient (client.Request should be used instead) --- .../Http/SettingsExtensionsTests.cs | 20 ++----------- Test/Flurl.Test/Http/SettingsTests.cs | 2 +- src/Flurl.CodeGen/Metadata.cs | 3 -- src/Flurl.Http/FlurlClient.cs | 3 +- src/Flurl.Http/GeneratedExtensions.cs | 30 ------------------- src/Flurl.Http/SettingsExtensions.cs | 11 ------- 6 files changed, 5 insertions(+), 64 deletions(-) diff --git a/Test/Flurl.Test/Http/SettingsExtensionsTests.cs b/Test/Flurl.Test/Http/SettingsExtensionsTests.cs index c3bd78de..df24338f 100644 --- a/Test/Flurl.Test/Http/SettingsExtensionsTests.cs +++ b/Test/Flurl.Test/Http/SettingsExtensionsTests.cs @@ -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"); @@ -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(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(async () => await req.GetAsync()); } } } diff --git a/Test/Flurl.Test/Http/SettingsTests.cs b/Test/Flurl.Test/Http/SettingsTests.cs index 1787c304..c45da28c 100644 --- a/Test/Flurl.Test/Http/SettingsTests.cs +++ b/Test/Flurl.Test/Http/SettingsTests.cs @@ -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"); diff --git a/src/Flurl.CodeGen/Metadata.cs b/src/Flurl.CodeGen/Metadata.cs index 757d1158..96045999 100644 --- a/src/Flurl.CodeGen/Metadata.cs +++ b/src/Flurl.CodeGen/Metadata.cs @@ -119,9 +119,6 @@ public static IEnumerable 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."); } /// diff --git a/src/Flurl.Http/FlurlClient.cs b/src/Flurl.Http/FlurlClient.cs index a2f267d3..982497dc 100644 --- a/src/Flurl.Http/FlurlClient.cs +++ b/src/Flurl.Http/FlurlClient.cs @@ -140,8 +140,7 @@ private bool ConnectionLeaseExpired() { public HttpMessageHandler HttpMessageHandler => HttpTest.Current?.HttpMessageHandler ?? _httpMessageHandler?.Value; /// - 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; diff --git a/src/Flurl.Http/GeneratedExtensions.cs b/src/Flurl.Http/GeneratedExtensions.cs index 107ddd37..ac363bc9 100644 --- a/src/Flurl.Http/GeneratedExtensions.cs +++ b/src/Flurl.Http/GeneratedExtensions.cs @@ -711,16 +711,6 @@ public static IFlurlRequest WithAutoRedirect(this Url url, bool enabled) { return new FlurlRequest(url).WithAutoRedirect(enabled); } - /// - /// Creates a new FlurlRequest and configures it to use the given IFlurlClient. - /// - /// This Flurl.Url. - /// The IFlurlClient to use to send the request. - /// A new IFlurlRequest. - public static IFlurlRequest WithClient(this Url url, IFlurlClient client) { - return new FlurlRequest(url).WithClient(client); - } - /// /// Creates a FlurlRequest and sends an asynchronous request. /// @@ -1160,16 +1150,6 @@ public static IFlurlRequest WithAutoRedirect(this string url, bool enabled) { return new FlurlRequest(url).WithAutoRedirect(enabled); } - /// - /// Creates a new FlurlRequest and configures it to use the given IFlurlClient. - /// - /// This URL. - /// The IFlurlClient to use to send the request. - /// A new IFlurlRequest. - public static IFlurlRequest WithClient(this string url, IFlurlClient client) { - return new FlurlRequest(url).WithClient(client); - } - /// /// Creates a FlurlRequest and sends an asynchronous request. /// @@ -1609,15 +1589,5 @@ public static IFlurlRequest WithAutoRedirect(this Uri uri, bool enabled) { return new FlurlRequest(uri).WithAutoRedirect(enabled); } - /// - /// Creates a new FlurlRequest and configures it to use the given IFlurlClient. - /// - /// This System.Uri. - /// The IFlurlClient to use to send the request. - /// A new IFlurlRequest. - public static IFlurlRequest WithClient(this Uri uri, IFlurlClient client) { - return new FlurlRequest(uri).WithClient(client); - } - } } diff --git a/src/Flurl.Http/SettingsExtensions.cs b/src/Flurl.Http/SettingsExtensions.cs index fd15dee6..1f1d58a8 100644 --- a/src/Flurl.Http/SettingsExtensions.cs +++ b/src/Flurl.Http/SettingsExtensions.cs @@ -33,17 +33,6 @@ public static IFlurlRequest ConfigureRequest(this IFlurlRequest request, Action< return request; } - /// - /// Fluently specify the IFlurlClient to use with this IFlurlRequest. - /// - /// The IFlurlRequest. - /// The IFlurlClient to use when sending the request. - /// A new IFlurlRequest to use in calling the Url - public static IFlurlRequest WithClient(this IFlurlRequest request, IFlurlClient client) { - request.Client = client; - return request; - } - /// /// Sets the timeout for this IFlurlRequest or all requests made with this IFlurlClient. ///