Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flurl.Http 4.0.0-pre7 #786

Merged
merged 4 commits into from
Dec 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#785 AllowHttpStatus should take int[]
Todd committed Dec 8, 2023
commit d9924c4012de89e07fa8fb15edebf591acb1ca44
4 changes: 2 additions & 2 deletions src/Flurl.CodeGen/Metadata.cs
Original file line number Diff line number Diff line change
@@ -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.");
18 changes: 9 additions & 9 deletions src/Flurl.Http/GeneratedExtensions.cs
Original file line number Diff line number Diff line change
@@ -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);
}

@@ -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);
}

@@ -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);
}

8 changes: 4 additions & 4 deletions src/Flurl.Http/ISettingsContainer.cs
Original file line number Diff line number Diff line change
@@ -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);
}

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