From d9924c4012de89e07fa8fb15edebf591acb1ca44 Mon Sep 17 00:00:00 2001 From: Todd Date: Thu, 7 Dec 2023 21:33:08 -0600 Subject: [PATCH] #785 AllowHttpStatus should take int[] --- src/Flurl.CodeGen/Metadata.cs | 4 ++-- src/Flurl.Http/GeneratedExtensions.cs | 18 +++++++++--------- src/Flurl.Http/ISettingsContainer.cs | 8 ++++---- test/Flurl.Test/Http/SettingsTests.cs | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Flurl.CodeGen/Metadata.cs b/src/Flurl.CodeGen/Metadata.cs index 9b8aa135..0bf9f392 100644 --- a/src/Flurl.CodeGen/Metadata.cs +++ b/src/Flurl.CodeGen/Metadata.cs @@ -139,8 +139,8 @@ public static IEnumerable GetRequestReturningExtensions(MethodA .AddArg("seconds", "int", "Seconds to wait before the request times out."); yield return Create("AllowHttpStatus", "Creates a new FlurlRequest and adds a pattern representing an HTTP status code or range of codes which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown.") .AddArg("pattern", "string", "Examples: \"3xx\", \"100,300,600\", \"100-299,6xx\""); - yield return Create("AllowHttpStatus", "Creates a new FlurlRequest and adds an HttpStatusCode which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown.") - .AddArg("statusCodes", "params HttpStatusCode[]", "The HttpStatusCode(s) to allow."); + yield return Create("AllowHttpStatus", "Creates a new FlurlRequest and adds one or more response status codes which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown.") + .AddArg("statusCodes", "params int[]", "One or more response status codes that, when received, will not cause an exception to be thrown."); 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."); diff --git a/src/Flurl.Http/GeneratedExtensions.cs b/src/Flurl.Http/GeneratedExtensions.cs index e197a350..397e2bd2 100644 --- a/src/Flurl.Http/GeneratedExtensions.cs +++ b/src/Flurl.Http/GeneratedExtensions.cs @@ -683,12 +683,12 @@ public static IFlurlRequest AllowHttpStatus(this Url url, string pattern) { } /// - /// Creates a new FlurlRequest and adds an HttpStatusCode which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown. + /// Creates a new FlurlRequest and adds one or more response status codes which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown. /// /// This Flurl.Url. - /// The HttpStatusCode(s) to allow. + /// One or more response status codes that, when received, will not cause an exception to be thrown. /// A new IFlurlRequest. - public static IFlurlRequest AllowHttpStatus(this Url url, params HttpStatusCode[] statusCodes) { + public static IFlurlRequest AllowHttpStatus(this Url url, params int[] statusCodes) { return new FlurlRequest(url).AllowHttpStatus(statusCodes); } @@ -1202,12 +1202,12 @@ public static IFlurlRequest AllowHttpStatus(this string url, string pattern) { } /// - /// Creates a new FlurlRequest and adds an HttpStatusCode which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown. + /// Creates a new FlurlRequest and adds one or more response status codes which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown. /// /// This URL. - /// The HttpStatusCode(s) to allow. + /// One or more response status codes that, when received, will not cause an exception to be thrown. /// A new IFlurlRequest. - public static IFlurlRequest AllowHttpStatus(this string url, params HttpStatusCode[] statusCodes) { + public static IFlurlRequest AllowHttpStatus(this string url, params int[] statusCodes) { return new FlurlRequest(url).AllowHttpStatus(statusCodes); } @@ -1721,12 +1721,12 @@ public static IFlurlRequest AllowHttpStatus(this Uri uri, string pattern) { } /// - /// Creates a new FlurlRequest and adds an HttpStatusCode which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown. + /// Creates a new FlurlRequest and adds one or more response status codes which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown. /// /// This System.Uri. - /// The HttpStatusCode(s) to allow. + /// One or more response status codes that, when received, will not cause an exception to be thrown. /// A new IFlurlRequest. - public static IFlurlRequest AllowHttpStatus(this Uri uri, params HttpStatusCode[] statusCodes) { + public static IFlurlRequest AllowHttpStatus(this Uri uri, params int[] statusCodes) { return new FlurlRequest(uri).AllowHttpStatus(statusCodes); } diff --git a/src/Flurl.Http/ISettingsContainer.cs b/src/Flurl.Http/ISettingsContainer.cs index 4f8f8254..698fd87f 100644 --- a/src/Flurl.Http/ISettingsContainer.cs +++ b/src/Flurl.Http/ISettingsContainer.cs @@ -72,13 +72,13 @@ public static T AllowHttpStatus(this T obj, string pattern) where T : ISettin } /// - /// Adds an which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown. + /// Adds one or more response status codes which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown. /// /// Object containing settings. - /// Examples: HttpStatusCode.NotFound + /// One or more response status codes that, when received, will not cause an exception to be thrown. /// This settings container. - public static T AllowHttpStatus(this T obj, params HttpStatusCode[] statusCodes) where T : ISettingsContainer { - var pattern = string.Join(",", statusCodes.Select(c => (int)c)); + public static T AllowHttpStatus(this T obj, params int[] statusCodes) where T : ISettingsContainer { + var pattern = string.Join(",", statusCodes); return AllowHttpStatus(obj, pattern); } diff --git a/test/Flurl.Test/Http/SettingsTests.cs b/test/Flurl.Test/Http/SettingsTests.cs index c263bdb3..ee5763c7 100644 --- a/test/Flurl.Test/Http/SettingsTests.cs +++ b/test/Flurl.Test/Http/SettingsTests.cs @@ -113,7 +113,7 @@ public void can_set_timeout_in_seconds() { public async Task can_allow_specific_http_status() { using var test = new HttpTest(); test.RespondWith("Nothing to see here", 404); - var c = CreateContainer().AllowHttpStatus(HttpStatusCode.Conflict, HttpStatusCode.NotFound); + var c = CreateContainer().AllowHttpStatus(409, 404); await GetRequest(c).DeleteAsync(); // no exception = pass } @@ -121,7 +121,7 @@ public async Task can_allow_specific_http_status() { public async Task allow_specific_http_status_also_allows_2xx() { using var test = new HttpTest(); test.RespondWith("I'm just an innocent 2xx, I should never fail!", 201); - var c = CreateContainer().AllowHttpStatus(HttpStatusCode.Conflict, HttpStatusCode.NotFound); + var c = CreateContainer().AllowHttpStatus(409, 404); await GetRequest(c).GetAsync(); // no exception = pass }