Flurl: Support Gzip in Requests

Created on 20 Dec 2017  ·  5Comments  ·  Source: tmenier/Flurl

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

Most helpful comment

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

All 5 comments

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!

Was this page helpful?
0 / 5 - 0 ratings