Skip to content
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

Add Transfer-Encoding compression support and extensible compression API #866

Merged
merged 3 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Release/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enable_testing()
set(WERROR ON CACHE BOOL "Treat Warnings as Errors.")
set(CPPREST_EXCLUDE_WEBSOCKETS OFF CACHE BOOL "Exclude websockets functionality.")
set(CPPREST_EXCLUDE_COMPRESSION OFF CACHE BOOL "Exclude compression functionality.")
BillyONeal marked this conversation as resolved.
Show resolved Hide resolved
set(CPPREST_EXCLUDE_BROTLI ON CACHE BOOL "Exclude Brotli compression functionality.")
set(CPPREST_EXPORT_DIR cpprestsdk CACHE STRING "Directory to install CMake config files.")
set(CPPREST_INSTALL_HEADERS ON CACHE BOOL "Install header files.")
set(CPPREST_INSTALL ON CACHE BOOL "Add install commands.")
Expand Down Expand Up @@ -62,6 +63,7 @@ include(cmake/cpprest_find_boost.cmake)
include(cmake/cpprest_find_zlib.cmake)
include(cmake/cpprest_find_openssl.cmake)
include(cmake/cpprest_find_websocketpp.cmake)
include(cmake/cpprest_find_brotli.cmake)
include(CheckIncludeFiles)
include(GNUInstallDirs)

Expand Down
10 changes: 10 additions & 0 deletions Release/cmake/cpprest_find_brotli.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function(cpprest_find_brotli)
if(TARGET cpprestsdk_brotli_internal)
return()
endif()

find_package(unofficial-brotli REQUIRED)

add_library(cpprestsdk_brotli_internal INTERFACE)
target_link_libraries(cpprestsdk_brotli_internal INTERFACE unofficial::brotli::brotlienc unofficial::brotli::brotlidec unofficial::brotli::brotlicommon)
endfunction()
4 changes: 4 additions & 0 deletions Release/cmake/cpprestsdk-config.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ if(@CPPREST_USES_ZLIB@)
find_dependency(ZLIB)
endif()

if(@CPPREST_USES_BROTLI@)
find_dependency(unofficial-brotli)
endif()

if(@CPPREST_USES_OPENSSL@)
find_dependency(OpenSSL)
endif()
Expand Down
2 changes: 1 addition & 1 deletion Release/include/cpprest/asyncrt_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ _ASYNCRTIMP const std::error_category & __cdecl linux_category();

/// <summary>
/// Gets the one global instance of the current platform's error category.
/// <summary>
/// </summary>
BillyONeal marked this conversation as resolved.
Show resolved Hide resolved
_ASYNCRTIMP const std::error_category & __cdecl platform_category();

/// <summary>
Expand Down
66 changes: 0 additions & 66 deletions Release/include/cpprest/details/http_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,70 +41,4 @@ namespace details
_ASYNCRTIMP size_t __cdecl add_chunked_delimiters(_Out_writes_(buffer_size) uint8_t *data, _In_ size_t buffer_size, size_t bytes_read);
}

namespace compression
{
enum class compression_algorithm : int
{
deflate = 15,
gzip = 31,
invalid = 9999
};

using data_buffer = std::vector<uint8_t>;

class stream_decompressor
{
public:

static compression_algorithm to_compression_algorithm(const utility::string_t& alg)
{
if (_XPLATSTR("gzip") == alg)
{
return compression_algorithm::gzip;
}
else if (_XPLATSTR("deflate") == alg)
{
return compression_algorithm::deflate;
}

return compression_algorithm::invalid;
}

static utility::string_t known_algorithms() { return _XPLATSTR("deflate, gzip"); }

_ASYNCRTIMP static bool __cdecl is_supported();

_ASYNCRTIMP stream_decompressor(compression_algorithm alg);

_ASYNCRTIMP data_buffer decompress(const data_buffer& input);

_ASYNCRTIMP data_buffer decompress(const uint8_t* input, size_t input_size);

_ASYNCRTIMP bool has_error() const;

private:
class stream_decompressor_impl;
std::shared_ptr<stream_decompressor_impl> m_pimpl;
};

class stream_compressor
{
public:

_ASYNCRTIMP static bool __cdecl is_supported();

_ASYNCRTIMP stream_compressor(compression_algorithm alg);

_ASYNCRTIMP data_buffer compress(const data_buffer& input, bool finish);

_ASYNCRTIMP data_buffer compress(const uint8_t* input, size_t input_size, bool finish);

_ASYNCRTIMP bool has_error() const;

private:
class stream_compressor_impl;
std::shared_ptr<stream_compressor_impl> m_pimpl;
};

}
}}}
12 changes: 7 additions & 5 deletions Release/include/cpprest/http_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,22 @@ class http_client_config
}

/// <summary>
/// Checks if requesting a compressed response is turned on, the default is off.
/// Checks if requesting a compressed response using Content-Encoding is turned on, the default is off.
/// </summary>
/// <returns>True if compressed response is enabled, false otherwise</returns>
/// <returns>True if a content-encoded compressed response is allowed, false otherwise</returns>
bool request_compressed_response() const
{
return m_request_compressed;
}

/// <summary>
/// Request that the server responds with a compressed body.
/// If true, in cases where the server does not support compression, this will have no effect.
/// Request that the server respond with a compressed body using Content-Encoding; to use Transfer-Encoding, do not
/// set this, and specify a vector of <see cref="web::http::details::comporession::decompress_factory" /> pointers
/// to the set_decompress_factories method of the <see cref="web::http::http_request" /> object for the request.
/// If true and the server does not support compression, this will have no effect.
/// The response body is internally decompressed before the consumer receives the data.
/// </summary>
/// <param name="request_compressed">True to turn on response body compression, false otherwise.</param>
/// <param name="request_compressed">True to turn on content-encoded response body compression, false otherwise.</param>
/// <remarks>Please note there is a performance cost due to copying the request data. Currently only supported on Windows and OSX.</remarks>
void set_request_compressed_response(bool request_compressed)
{
Expand Down
Loading