-
Notifications
You must be signed in to change notification settings - Fork 3
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
v2.0.0 release #7
Conversation
Looks great! Though most of these are the changes that I tried to get merged 3 years ago 😆 |
@snake-4 do you mean PR #5? Most of those things (4 out of 7) were actually released last year 🙂. For the remaining ones:
The focus of 2.0 is the new serialization and deserialization system, along with better documentation on how to use it correctly, especially with Thanks for the feedback! |
I had implemented client disposal by discarding least recently used HttpClient and also by keeping track of last access timestamps for them. |
Draft of release notes:
Changes
Flurl
dependency (URL builder) to v4 (6098e03, d7d2a27)EnsureSuccessStatusCode
method on the response (5f1c96b)StatusCode
property on the response (4503c87)IHttpClientFactory.GetProxiedClient()
now has the request URI parameter too (06677e9)JsonPayload
,XmlPayload
,FormUrlEncodedPayload
,PlainTextPayload
and removed theContentType
property (924b708, 7548e3c)ReadBody
,DownloadFileName
,ResponseEncoding
properties from the request and added newRead*
methods to the responseHttpClientFactory
can now be customized without replacing it (bbb7cbb, 6a960d3)HttpRequest
was removedTimeout
property on the request was changed fromTimeSpan.Zero
toSystem.Threading.Timeout.InfiniteTimeSpan
(9fa8d4c)Upgrading from v1.x
Response reading and deserialization changes
If you used the
Body
property on the response, you should now use one of these methods to obtain the response:Task<Stream> ReadStream()
Task<string> ReadString()
Task<string> ReadString(Encoding encoding)
Task<T?> ReadJson<T>(JsonSerializerOptions? options = null)
Task<string> DownloadFile(string path)
Task<T?> ReadXml<T>(XmlReaderSettings? settings = null)
Task<byte[]> ReadBytes()
All these methods except for
ReadStream
take into account the request timeout.The updated README covers these methods, their usage and their pitfalls in greater detail.
Request serialization changes
If you used the request serialization feature, you should remove the
ContentType
property from requests and instead set thePayload
with an instance of any class implementing theIPayload
interface. Pass your payload to the constructor of these classes.The library provides implementations for the following payload types:
JsonPayload
(based onSystem.Text.Json
)XmlPayload
(now with UTF-8 encoding instead of UTF-16)FormUrlEncodedPayload
PlainTextPayload
With more likely coming in the future.
The updated README contains instructions on how to extend this mechanism and create new payload types.
Custom
HttpClientFactory
sIf you implemented your own
IHttpClientFactory
and/or inherited fromHttpClientFactory
, you must change the signature of theGetProxiedClient
method as follows:public HttpClient GetProxiedClient(Uri requestUri, Uri proxyUri)
Also, the default factory now allows for some basic customizations which weren't possible before without swapping the factory implementation. The updated README covers these new options in detail, which might remove the need for replacing the factory implementation altogether.
Default
Timeout
If you relied on the fact that the default value of
Timeout
onHttpRequest
wasTimeSpan.Zero
, the new default isSystem.Threading.Timeout.InfiniteTimeSpan
(as it should always have been).