Skip to content

Commit

Permalink
#785 AllowHttpStatus should take int[]
Browse files Browse the repository at this point in the history
  • Loading branch information
Todd committed Dec 8, 2023
1 parent 4def7d7 commit d9924c4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Flurl.CodeGen/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public static IEnumerable<ExtensionMethod> 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.");
Expand Down
18 changes: 9 additions & 9 deletions src/Flurl.Http/GeneratedExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,12 +683,12 @@ public static IFlurlRequest AllowHttpStatus(this Url url, string pattern) {
}

/// <summary>
/// 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.
/// </summary>
/// <param name="url">This Flurl.Url.</param>
/// <param name="statusCodes">The HttpStatusCode(s) to allow.</param>
/// <param name="statusCodes">One or more response status codes that, when received, will not cause an exception to be thrown.</param>
/// <returns>A new IFlurlRequest.</returns>
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);
}

Expand Down Expand Up @@ -1202,12 +1202,12 @@ public static IFlurlRequest AllowHttpStatus(this string url, string pattern) {
}

/// <summary>
/// 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.
/// </summary>
/// <param name="url">This URL.</param>
/// <param name="statusCodes">The HttpStatusCode(s) to allow.</param>
/// <param name="statusCodes">One or more response status codes that, when received, will not cause an exception to be thrown.</param>
/// <returns>A new IFlurlRequest.</returns>
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);
}

Expand Down Expand Up @@ -1721,12 +1721,12 @@ public static IFlurlRequest AllowHttpStatus(this Uri uri, string pattern) {
}

/// <summary>
/// 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.
/// </summary>
/// <param name="uri">This System.Uri.</param>
/// <param name="statusCodes">The HttpStatusCode(s) to allow.</param>
/// <param name="statusCodes">One or more response status codes that, when received, will not cause an exception to be thrown.</param>
/// <returns>A new IFlurlRequest.</returns>
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);
}

Expand Down
8 changes: 4 additions & 4 deletions src/Flurl.Http/ISettingsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ public static T AllowHttpStatus<T>(this T obj, string pattern) where T : ISettin
}

/// <summary>
/// Adds an <see cref="HttpStatusCode" /> 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.
/// </summary>
/// <param name="obj">Object containing settings.</param>
/// <param name="statusCodes">Examples: HttpStatusCode.NotFound</param>
/// <param name="statusCodes">One or more response status codes that, when received, will not cause an exception to be thrown.</param>
/// <returns>This settings container.</returns>
public static T AllowHttpStatus<T>(this T obj, params HttpStatusCode[] statusCodes) where T : ISettingsContainer {
var pattern = string.Join(",", statusCodes.Select(c => (int)c));
public static T AllowHttpStatus<T>(this T obj, params int[] statusCodes) where T : ISettingsContainer {
var pattern = string.Join(",", statusCodes);
return AllowHttpStatus(obj, pattern);
}

Expand Down
4 changes: 2 additions & 2 deletions test/Flurl.Test/Http/SettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ 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
}

[Test]
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
}

Expand Down

0 comments on commit d9924c4

Please sign in to comment.