Skip to content

Commit 74da372

Browse files
authored
Merge pull request #866 from epistor/compress
Add Transfer-Encoding compression support and extensible compression API
2 parents 61e4933 + edc5ad8 commit 74da372

26 files changed

+4285
-626
lines changed

Release/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enable_testing()
1818
set(WERROR ON CACHE BOOL "Treat Warnings as Errors.")
1919
set(CPPREST_EXCLUDE_WEBSOCKETS OFF CACHE BOOL "Exclude websockets functionality.")
2020
set(CPPREST_EXCLUDE_COMPRESSION OFF CACHE BOOL "Exclude compression functionality.")
21+
set(CPPREST_EXCLUDE_BROTLI ON CACHE BOOL "Exclude Brotli compression functionality.")
2122
set(CPPREST_EXPORT_DIR cpprestsdk CACHE STRING "Directory to install CMake config files.")
2223
set(CPPREST_INSTALL_HEADERS ON CACHE BOOL "Install header files.")
2324
set(CPPREST_INSTALL ON CACHE BOOL "Add install commands.")
@@ -62,6 +63,7 @@ include(cmake/cpprest_find_boost.cmake)
6263
include(cmake/cpprest_find_zlib.cmake)
6364
include(cmake/cpprest_find_openssl.cmake)
6465
include(cmake/cpprest_find_websocketpp.cmake)
66+
include(cmake/cpprest_find_brotli.cmake)
6567
include(CheckIncludeFiles)
6668
include(GNUInstallDirs)
6769

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function(cpprest_find_brotli)
2+
if(TARGET cpprestsdk_brotli_internal)
3+
return()
4+
endif()
5+
6+
find_package(unofficial-brotli REQUIRED)
7+
8+
add_library(cpprestsdk_brotli_internal INTERFACE)
9+
target_link_libraries(cpprestsdk_brotli_internal INTERFACE unofficial::brotli::brotlienc unofficial::brotli::brotlidec unofficial::brotli::brotlicommon)
10+
endfunction()

Release/cmake/cpprestsdk-config.in.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ if(@CPPREST_USES_ZLIB@)
33
find_dependency(ZLIB)
44
endif()
55

6+
if(@CPPREST_USES_BROTLI@)
7+
find_dependency(unofficial-brotli)
8+
endif()
9+
610
if(@CPPREST_USES_OPENSSL@)
711
find_dependency(OpenSSL)
812
endif()

Release/include/cpprest/asyncrt_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ _ASYNCRTIMP const std::error_category & __cdecl linux_category();
503503

504504
/// <summary>
505505
/// Gets the one global instance of the current platform's error category.
506-
/// <summary>
506+
/// </summary>
507507
_ASYNCRTIMP const std::error_category & __cdecl platform_category();
508508

509509
/// <summary>

Release/include/cpprest/details/http_helpers.h

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -41,70 +41,4 @@ namespace details
4141
_ASYNCRTIMP size_t __cdecl add_chunked_delimiters(_Out_writes_(buffer_size) uint8_t *data, _In_ size_t buffer_size, size_t bytes_read);
4242
}
4343

44-
namespace compression
45-
{
46-
enum class compression_algorithm : int
47-
{
48-
deflate = 15,
49-
gzip = 31,
50-
invalid = 9999
51-
};
52-
53-
using data_buffer = std::vector<uint8_t>;
54-
55-
class stream_decompressor
56-
{
57-
public:
58-
59-
static compression_algorithm to_compression_algorithm(const utility::string_t& alg)
60-
{
61-
if (_XPLATSTR("gzip") == alg)
62-
{
63-
return compression_algorithm::gzip;
64-
}
65-
else if (_XPLATSTR("deflate") == alg)
66-
{
67-
return compression_algorithm::deflate;
68-
}
69-
70-
return compression_algorithm::invalid;
71-
}
72-
73-
static utility::string_t known_algorithms() { return _XPLATSTR("deflate, gzip"); }
74-
75-
_ASYNCRTIMP static bool __cdecl is_supported();
76-
77-
_ASYNCRTIMP stream_decompressor(compression_algorithm alg);
78-
79-
_ASYNCRTIMP data_buffer decompress(const data_buffer& input);
80-
81-
_ASYNCRTIMP data_buffer decompress(const uint8_t* input, size_t input_size);
82-
83-
_ASYNCRTIMP bool has_error() const;
84-
85-
private:
86-
class stream_decompressor_impl;
87-
std::shared_ptr<stream_decompressor_impl> m_pimpl;
88-
};
89-
90-
class stream_compressor
91-
{
92-
public:
93-
94-
_ASYNCRTIMP static bool __cdecl is_supported();
95-
96-
_ASYNCRTIMP stream_compressor(compression_algorithm alg);
97-
98-
_ASYNCRTIMP data_buffer compress(const data_buffer& input, bool finish);
99-
100-
_ASYNCRTIMP data_buffer compress(const uint8_t* input, size_t input_size, bool finish);
101-
102-
_ASYNCRTIMP bool has_error() const;
103-
104-
private:
105-
class stream_compressor_impl;
106-
std::shared_ptr<stream_compressor_impl> m_pimpl;
107-
};
108-
109-
}
11044
}}}

Release/include/cpprest/http_client.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,22 @@ class http_client_config
247247
}
248248

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

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

0 commit comments

Comments
 (0)