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

4.0.1 #791

Merged
merged 6 commits into from
Jan 10, 2024
Merged

4.0.1 #791

Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: tmenier
1 change: 1 addition & 0 deletions src/Flurl.CodeGen/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private static void WriteHttpExtensionMethod(CodeWriter writer, HttpExtensionMet
args.Add("cancellationToken");

if (xm.RequestBodyType != null) {
writer.WriteLine("request.EnsureClient();"); // might need to serialize body, and client might provide custom serializer
writer.WriteLine("var content = new Captured@0Content(@1);",
xm.RequestBodyType,
xm.RequestBodyType == "String" ? "body" : $"request.Settings.{xm.RequestBodyType}Serializer.Serialize(body)");
Expand Down
4 changes: 2 additions & 2 deletions src/Flurl.Http.Newtonsoft/Flurl.Http.Newtonsoft.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<LangVersion>9.0</LangVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Flurl.Http.Newtonsoft</PackageId>
<Version>0.9.0</Version>
<Version>0.9.1</Version>
<Authors>Todd Menier</Authors>
<Description>A Newtonsoft-based JSON serializer for Flurl.Http 4.0 and above.</Description>
<Copyright>Copyright (c) Todd Menier 2023.</Copyright>
<Copyright>Copyright (c) Todd Menier 2024.</Copyright>
<PackageProjectUrl>https://flurl.dev</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/tmenier/Flurl.git</RepositoryUrl>
Expand Down
6 changes: 3 additions & 3 deletions src/Flurl.Http/Flurl.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<LangVersion>9.0</LangVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageId>Flurl.Http</PackageId>
<Version>4.0.0</Version>
<Version>4.0.1</Version>
<Authors>Todd Menier</Authors>
<Description>4.0 contains breaking changes! See flurl.dev/upgrade</Description>
<Copyright>Copyright (c) Todd Menier 2023.</Copyright>
<Description>A fluent, testable HTTP client library.</Description>
<Copyright>Copyright (c) Todd Menier 2024.</Copyright>
<PackageProjectUrl>https://flurl.dev</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
12 changes: 10 additions & 2 deletions src/Flurl.Http/FlurlRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public interface IFlurlRequest : ISettingsContainer, IHeadersContainer, IEventHa
/// </summary>
FlurlCall RedirectedFrom { get; set; }

/// <summary>
/// If Client property is null, selects (or creates) a FlurlClient from the global FlurlHttp.Clients cache. Called
/// automatically just before a request is sent, so in most cases there is no need to call explicitly.
/// </summary>
IFlurlClient EnsureClient();

/// <summary>
/// Asynchronously sends the HTTP request. Mainly used to implement higher-level extension methods (GetJsonAsync, etc).
/// </summary>
Expand Down Expand Up @@ -138,12 +144,14 @@ public CookieJar CookieJar {
set => ApplyCookieJar(value);
}

/// <inheritdoc />
public IFlurlClient EnsureClient() => Client ??= FlurlHttp.GetClientForRequest(this);

/// <inheritdoc />
public Task<IFlurlResponse> SendAsync(HttpMethod verb, HttpContent content = null, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
Verb = verb;
Content = content;
Client ??= FlurlHttp.GetClientForRequest(this);
return Client.SendAsync(this, completionOption, cancellationToken);
return EnsureClient().SendAsync(this, completionOption, cancellationToken);
}

internal static void SyncHeaders(IFlurlClient client, IFlurlRequest request) {
Expand Down
10 changes: 10 additions & 0 deletions src/Flurl.Http/GeneratedExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public static class GeneratedExtensions
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> SendJsonAsync(this IFlurlRequest request, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(body));
return request.SendAsync(verb, content, completionOption, cancellationToken);
}
Expand All @@ -39,6 +40,7 @@ public static Task<IFlurlResponse> SendJsonAsync(this IFlurlRequest request, Htt
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> SendStringAsync(this IFlurlRequest request, HttpMethod verb, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedStringContent(body);
return request.SendAsync(verb, content, completionOption, cancellationToken);
}
Expand All @@ -53,6 +55,7 @@ public static Task<IFlurlResponse> SendStringAsync(this IFlurlRequest request, H
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> SendUrlEncodedAsync(this IFlurlRequest request, HttpMethod verb, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedUrlEncodedContent(request.Settings.UrlEncodedSerializer.Serialize(body));
return request.SendAsync(verb, content, completionOption, cancellationToken);
}
Expand Down Expand Up @@ -133,6 +136,7 @@ public static Task<IFlurlResponse> PostAsync(this IFlurlRequest request, HttpCon
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> PostJsonAsync(this IFlurlRequest request, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(body));
return request.SendAsync(HttpMethod.Post, content, completionOption, cancellationToken);
}
Expand All @@ -146,6 +150,7 @@ public static Task<IFlurlResponse> PostJsonAsync(this IFlurlRequest request, obj
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> PostStringAsync(this IFlurlRequest request, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedStringContent(body);
return request.SendAsync(HttpMethod.Post, content, completionOption, cancellationToken);
}
Expand All @@ -159,6 +164,7 @@ public static Task<IFlurlResponse> PostStringAsync(this IFlurlRequest request, s
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> PostUrlEncodedAsync(this IFlurlRequest request, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedUrlEncodedContent(request.Settings.UrlEncodedSerializer.Serialize(body));
return request.SendAsync(HttpMethod.Post, content, completionOption, cancellationToken);
}
Expand Down Expand Up @@ -195,6 +201,7 @@ public static Task<IFlurlResponse> PutAsync(this IFlurlRequest request, HttpCont
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> PutJsonAsync(this IFlurlRequest request, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(body));
return request.SendAsync(HttpMethod.Put, content, completionOption, cancellationToken);
}
Expand All @@ -208,6 +215,7 @@ public static Task<IFlurlResponse> PutJsonAsync(this IFlurlRequest request, obje
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> PutStringAsync(this IFlurlRequest request, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedStringContent(body);
return request.SendAsync(HttpMethod.Put, content, completionOption, cancellationToken);
}
Expand Down Expand Up @@ -244,6 +252,7 @@ public static Task<IFlurlResponse> PatchAsync(this IFlurlRequest request, HttpCo
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> PatchJsonAsync(this IFlurlRequest request, object body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedJsonContent(request.Settings.JsonSerializer.Serialize(body));
return request.SendAsync(new HttpMethod("PATCH"), content, completionOption, cancellationToken);
}
Expand All @@ -257,6 +266,7 @@ public static Task<IFlurlResponse> PatchJsonAsync(this IFlurlRequest request, ob
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>A Task whose result is the received IFlurlResponse.</returns>
public static Task<IFlurlResponse> PatchStringAsync(this IFlurlRequest request, string body, HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead, CancellationToken cancellationToken = default) {
request.EnsureClient();
var content = new CapturedStringContent(body);
return request.SendAsync(new HttpMethod("PATCH"), content, completionOption, cancellationToken);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Flurl/Flurl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Version>4.0.0</Version>
<Authors>Todd Menier</Authors>
<Description>A fluent, portable URL builder. To make HTTP calls off the fluent chain, check out Flurl.Http.</Description>
<Copyright>Copyright (c) Todd Menier 2023.</Copyright>
<Copyright>Copyright (c) Todd Menier 2024.</Copyright>
<PackageProjectUrl>https://flurl.dev</PackageProjectUrl>
<PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>https://github.com/tmenier/Flurl.git</RepositoryUrl>
Expand Down
4 changes: 1 addition & 3 deletions test/Flurl.Test/Http/HttpTestFixtureBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ public abstract class HttpTestFixtureBase

[SetUp]
public void SetUp() {
HttpTest = CreateHttpTest();
HttpTest = new HttpTest();
}

[TearDown]
public void TearTown() {
HttpTest.Dispose();
}

protected virtual HttpTest CreateHttpTest() => new HttpTest();
}
}
Loading