cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

Supporting HTTP Compression

Open deeringc opened this issue 10 years ago • 11 comments

As far as I can tell there is currently no support for HTTP compression in neither the WinHTTP Client (WinHTTP itself doesn't seem to support it either, whereas WinInet does) nor the Boost ASIO Client. I'm looking into the possibility of adding support. Before I start I want to get some guidance on which external dependencies you would advise/accept.

The 2 immediate options are using zlib directly or using a C++ wrapper like boost::iostreams::gzip. The ASIO based client is clearly already strongly dependent on Boost, but would it be a problem to add a dependency for the Windows code (I would obviously like to share a common decompression component between the 2 impls)? Maybe there are other options apart from a zlib based approach?

Thanks, Chris

deeringc avatar Aug 23 '16 20:08 deeringc

I think taking the zlib-based approach is the best option, with a build flag to disable it. Zlib is extremely non-intrusive and lightweight; I'd prefer depending on that over boost when possible.

Plus, we already depend on it via OpenSSL on all platforms (when building websockets).

ras0219-msft avatar Aug 23 '16 21:08 ras0219-msft

This would be a great feature. I've used Boost to compress the body contents of POSTs prior to sending the request, and added the appropriate content-encoding header. and that seems to work as well.

samhatchett avatar Aug 23 '16 21:08 samhatchett

Ok great. @ras0219-msft I'll use zlib directly. Are there existing cases where a feature is optionally included based on a compile time flag. I'd like to make sure I'm following the right pattern across the different build systems.

@samhatchett my primary use case is supporting retrieving compressed content and decompressing. But if I have time I'll add support for sending compressed content as well.

deeringc avatar Aug 26 '16 08:08 deeringc

I think for now it would be best to tie it to the CPPREST_EXCLUDE_WEBSOCKETS flag to maintain the possibility of dependency-free builds on Windows, even though that seems really misleading right now.

The flag probably needs to be renamed something more like CPPREST_NO_DEPENDENCIES_ON_WINDOWS in the future, since that's what it's actually used for most of the time; I doubt anyone is building with that flag on Linux/OSX.

ras0219-msft avatar Aug 26 '16 21:08 ras0219-msft

Ok, sounds good. What's the best way to add zlib as a dependency?

Options as I see them are:

  1. Add https://github.com/madler/zlib as a git submodule, and conditionally build it from source.
  2. Bundle the source within the Casablanca repo, and conditionally build it from source.
  3. Bundle the (very small) required binaries within the Casablanca repo.
  4. Require the consumer to provide the dynamic libraries themselves if they choose to enable the feature.

If we go with 4 it would probably make sense to use a dedicated compilation flag to enable it.

deeringc avatar Aug 28 '16 21:08 deeringc

You missed an option: What about Nuget? I would be very surprised if it is not available on there.

GR

Sent from my Nexus 5.

On 28 Aug 2016 10:16 p.m., "deeringc" [email protected] wrote:

Ok, sounds good. What's the best way to add zlib as a dependency?

Options as I see them are:

  1. Add https://github.com/madler/zlib as a git submodule, and conditionally build it from source.
  2. Bundle the source within the Casablanca repo, and conditionally build it from source.
  3. Bundle the (very small) required binaries within the Casablanca repo.
  4. Require the consumer to provide the dynamic libraries themselves if they choose to enable the feature.

If we go with 4 it would probably make sense to use a dedicated compilation flag to enable it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Microsoft/cpprestsdk/issues/226#issuecomment-242999942, or mute the thread https://github.com/notifications/unsubscribe-auth/AEy9nGMvrSHq7ICg30ci0T3c2cqcdXBWks5qkfqugaJpZM4JrWX8 .

grahamreeds avatar Aug 29 '16 07:08 grahamreeds

Not an option for OSX I'm afraid.

deeringc avatar Aug 29 '16 10:08 deeringc

Should this issue be closed? The feature seems available since 21 Oct 2017:

https://github.com/Microsoft/cpprestsdk/releases/tag/v2.10.0 "PR https://github.com/Microsoft/cpprestsdk/pull/233 adds compression support (deflate and gzip) for Windows Desktop and ASIO http_clients based on Zlib."

heidemn avatar Jan 25 '18 14:01 heidemn

Yep, thanks!

ras0219-msft avatar Jan 25 '18 15:01 ras0219-msft

Is the compression support for http_client compiled by default or we need to enable it? Thanks.

shaopeng-lin avatar Mar 21 '19 16:03 shaopeng-lin

How to use request compression/decompression: https://github.com/microsoft/cpprestsdk/blob/96e7d20e398b629de2935f9ac32cfa2780cd0b0b/Release/tests/functional/http/client/outside_tests.cpp#L65-L89

KindDragon avatar Feb 14 '20 14:02 KindDragon