Flurl
Flurl copied to clipboard
Support Gzip in Requests
This idea was first discussed here.
It would be nice if Flurl would natively support gzip uploading of strings and files and such. Something like so:
// gzip a string
var t = await "https://www.example.com"
.WithHeader("Content-Type", "application/json")
.WithHeader("Content-Encoding", "gzip")
.PostGZipStringAsync(clear_text_json);
// gzip a text file
var t = await "https://www.example.com"
.WithHeader("Content-Type", "application/json")
.WithHeader("Content-Encoding", "gzip")
.PostAsync(new GzipFileContent(filePath))
An implementation for GZipFileContent was proposed here and @tmenier proposed using CompressedContent.
Using CompressedContent
, the result looks like this (for posting a string)
var t = await "https://www.example.com"
.WithHeader("Content-Type", "application/json")
.PostAsync(new CompressedContent(new StringContent(statusMessage), "gzip"));
It would also be nice to have a setting to enable compression for json content.
@Maly-Lemire Do you mean compressed JSON responses? Support for that (by default) was added in #266. If you mean compressed JSON requests (i.e. posted data), that's what this issue is all about.
@tmenier, can you rename this issue to “Support Gzip in Requests” and change title of https://github.com/tmenier/Flurl/issues/266 to mention “Response”? I’ve read https://github.com/tmenier/Flurl/issues/266 first and decided that flurl defaults gzip for both Requests and Responses
@MNF I renamed this one (since I opened it, I can rename it) I'll let @tmenier rename the other if he wants to.
I'm actively gathering feedback to help prioritize issues for 3.0. If this one is important to you, please vote for it here!
This never made it into 3.0 obviously but I'm still considering it. Funny thing is the .NET team has the same question I do: is it a common enough use case to warrant first-class support?
https://github.com/dotnet/runtime/issues/46944
Based on that issue and more general Googling, it's surprising how little interest/discussion there seems to be in the .NET world around request compression. I like to be careful not to bloat Flurl with support for "fringe" features. Still, this seemed to be a relatively popular feature request in Flurl a couple years ago and if people are still wanting it, it wouldn't take much to convince me. Filling "gaps" in the HttpClient stack has always been one of the goals of this project.
In any event, the above issue contains an updated version of that decade-old CompressedContent
class, which is perfectly compatible with Flurl, if anyone's interested.
It's common. Add it. 👍
A few years ago we considered to send gzip requests from our server to another service that was running in nginx on kubernetis. On that time we were advised that nginx/kubernetis didn't support it. Haven't check kubernetis config since then.