Flurl icon indicating copy to clipboard operation
Flurl copied to clipboard

Support Gzip in Requests

Open dagostinelli opened this issue 7 years ago • 8 comments

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"));

dagostinelli avatar Dec 20 '17 02:12 dagostinelli

It would also be nice to have a setting to enable compression for json content.

Maly-Lemire avatar Mar 16 '18 01:03 Maly-Lemire

@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 avatar Apr 01 '18 13:04 tmenier

@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 avatar Oct 04 '18 11:10 MNF

@MNF I renamed this one (since I opened it, I can rename it) I'll let @tmenier rename the other if he wants to.

dagostinelli avatar Oct 08 '18 01:10 dagostinelli

I'm actively gathering feedback to help prioritize issues for 3.0. If this one is important to you, please vote for it here!

tmenier avatar Apr 06 '19 14:04 tmenier

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.

tmenier avatar May 15 '22 14:05 tmenier

It's common. Add it. 👍

dagostinelli avatar May 16 '22 04:05 dagostinelli

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.

MNF avatar May 16 '22 10:05 MNF