Skip to content

Commit d9924c4

Browse files
author
Todd
committed
#785 AllowHttpStatus should take int[]
1 parent 4def7d7 commit d9924c4

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/Flurl.CodeGen/Metadata.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ public static IEnumerable<ExtensionMethod> GetRequestReturningExtensions(MethodA
139139
.AddArg("seconds", "int", "Seconds to wait before the request times out.");
140140
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.")
141141
.AddArg("pattern", "string", "Examples: \"3xx\", \"100,300,600\", \"100-299,6xx\"");
142-
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.")
143-
.AddArg("statusCodes", "params HttpStatusCode[]", "The HttpStatusCode(s) to allow.");
142+
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.")
143+
.AddArg("statusCodes", "params int[]", "One or more response status codes that, when received, will not cause an exception to be thrown.");
144144
yield return Create("AllowAnyHttpStatus", "Creates a new FlurlRequest and configures it to allow any returned HTTP status without throwing a FlurlHttpException.");
145145
yield return Create("WithAutoRedirect", "Creates a new FlurlRequest and configures whether redirects are automatically followed.")
146146
.AddArg("enabled", "bool", "true if Flurl should automatically send a new request to the redirect URL, false if it should not.");

src/Flurl.Http/GeneratedExtensions.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -683,12 +683,12 @@ public static IFlurlRequest AllowHttpStatus(this Url url, string pattern) {
683683
}
684684

685685
/// <summary>
686-
/// Creates a new FlurlRequest and adds an HttpStatusCode which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown.
686+
/// 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.
687687
/// </summary>
688688
/// <param name="url">This Flurl.Url.</param>
689-
/// <param name="statusCodes">The HttpStatusCode(s) to allow.</param>
689+
/// <param name="statusCodes">One or more response status codes that, when received, will not cause an exception to be thrown.</param>
690690
/// <returns>A new IFlurlRequest.</returns>
691-
public static IFlurlRequest AllowHttpStatus(this Url url, params HttpStatusCode[] statusCodes) {
691+
public static IFlurlRequest AllowHttpStatus(this Url url, params int[] statusCodes) {
692692
return new FlurlRequest(url).AllowHttpStatus(statusCodes);
693693
}
694694

@@ -1202,12 +1202,12 @@ public static IFlurlRequest AllowHttpStatus(this string url, string pattern) {
12021202
}
12031203

12041204
/// <summary>
1205-
/// Creates a new FlurlRequest and adds an HttpStatusCode which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown.
1205+
/// 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.
12061206
/// </summary>
12071207
/// <param name="url">This URL.</param>
1208-
/// <param name="statusCodes">The HttpStatusCode(s) to allow.</param>
1208+
/// <param name="statusCodes">One or more response status codes that, when received, will not cause an exception to be thrown.</param>
12091209
/// <returns>A new IFlurlRequest.</returns>
1210-
public static IFlurlRequest AllowHttpStatus(this string url, params HttpStatusCode[] statusCodes) {
1210+
public static IFlurlRequest AllowHttpStatus(this string url, params int[] statusCodes) {
12111211
return new FlurlRequest(url).AllowHttpStatus(statusCodes);
12121212
}
12131213

@@ -1721,12 +1721,12 @@ public static IFlurlRequest AllowHttpStatus(this Uri uri, string pattern) {
17211721
}
17221722

17231723
/// <summary>
1724-
/// Creates a new FlurlRequest and adds an HttpStatusCode which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown.
1724+
/// 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.
17251725
/// </summary>
17261726
/// <param name="uri">This System.Uri.</param>
1727-
/// <param name="statusCodes">The HttpStatusCode(s) to allow.</param>
1727+
/// <param name="statusCodes">One or more response status codes that, when received, will not cause an exception to be thrown.</param>
17281728
/// <returns>A new IFlurlRequest.</returns>
1729-
public static IFlurlRequest AllowHttpStatus(this Uri uri, params HttpStatusCode[] statusCodes) {
1729+
public static IFlurlRequest AllowHttpStatus(this Uri uri, params int[] statusCodes) {
17301730
return new FlurlRequest(uri).AllowHttpStatus(statusCodes);
17311731
}
17321732

src/Flurl.Http/ISettingsContainer.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ public static T AllowHttpStatus<T>(this T obj, string pattern) where T : ISettin
7272
}
7373

7474
/// <summary>
75-
/// Adds an <see cref="HttpStatusCode" /> which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown.
75+
/// Adds one or more response status codes which (in addition to 2xx) will NOT result in a FlurlHttpException being thrown.
7676
/// </summary>
7777
/// <param name="obj">Object containing settings.</param>
78-
/// <param name="statusCodes">Examples: HttpStatusCode.NotFound</param>
78+
/// <param name="statusCodes">One or more response status codes that, when received, will not cause an exception to be thrown.</param>
7979
/// <returns>This settings container.</returns>
80-
public static T AllowHttpStatus<T>(this T obj, params HttpStatusCode[] statusCodes) where T : ISettingsContainer {
81-
var pattern = string.Join(",", statusCodes.Select(c => (int)c));
80+
public static T AllowHttpStatus<T>(this T obj, params int[] statusCodes) where T : ISettingsContainer {
81+
var pattern = string.Join(",", statusCodes);
8282
return AllowHttpStatus(obj, pattern);
8383
}
8484

test/Flurl.Test/Http/SettingsTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ public void can_set_timeout_in_seconds() {
113113
public async Task can_allow_specific_http_status() {
114114
using var test = new HttpTest();
115115
test.RespondWith("Nothing to see here", 404);
116-
var c = CreateContainer().AllowHttpStatus(HttpStatusCode.Conflict, HttpStatusCode.NotFound);
116+
var c = CreateContainer().AllowHttpStatus(409, 404);
117117
await GetRequest(c).DeleteAsync(); // no exception = pass
118118
}
119119

120120
[Test]
121121
public async Task allow_specific_http_status_also_allows_2xx() {
122122
using var test = new HttpTest();
123123
test.RespondWith("I'm just an innocent 2xx, I should never fail!", 201);
124-
var c = CreateContainer().AllowHttpStatus(HttpStatusCode.Conflict, HttpStatusCode.NotFound);
124+
var c = CreateContainer().AllowHttpStatus(409, 404);
125125
await GetRequest(c).GetAsync(); // no exception = pass
126126
}
127127

0 commit comments

Comments
 (0)