Skip to content

Commit ded2dc0

Browse files
committed
wip
2 parents 41520ca + 655dd46 commit ded2dc0

File tree

11 files changed

+840
-48
lines changed

11 files changed

+840
-48
lines changed

Release/CMakeLists.txt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ elseif(ANDROID)
7575
option(BUILD_SHARED_LIBS "Build shared Libraries." OFF)
7676
set(BUILD_SAMPLES OFF)
7777
elseif(UNIX) # This includes OSX
78-
find_package(Boost 1.54 REQUIRED COMPONENTS random chrono system thread regex filesystem)
78+
find_package(Boost REQUIRED COMPONENTS random chrono system thread regex filesystem)
7979
find_package(Threads REQUIRED)
8080
if(APPLE AND NOT OPENSSL_ROOT_DIR)
8181
# Prefer a homebrew version of OpenSSL over the one in /usr/lib
@@ -88,6 +88,18 @@ elseif(UNIX) # This includes OSX
8888
find_package(OpenSSL 1.0.0 REQUIRED)
8989

9090
option(BUILD_SHARED_LIBS "Build shared Libraries." ON)
91+
92+
# Prefer the homebrew version of zlib
93+
find_library(ZLIB_LIBRARIES NAMES libz.a PATHS /usr/local/Cellar/zlib/1.2.8/lib NO_DEFAULT_PATH)
94+
find_path(ZLIB_INCLUDE_DIRS NAMES zlib.h PATHS /usr/local/Cellar/zlib/1.2.8/include NO_DEFAULT_PATH)
95+
96+
if(NOT ZLIB_LIBRARIES OR NOT ZLIB_INCLUDE_DIRS)
97+
find_package(ZLIB)
98+
if(NOT ZLIB_FOUND)
99+
option(CPPREST_EXCLUDE_COMPRESSION "Exclude compression functionality." ON)
100+
endif()
101+
endif()
102+
91103
option(BUILD_SAMPLES "Build samples." ON)
92104
option(CASA_INSTALL_HEADERS "Install header files." ON)
93105
if(CASA_INSTALL_HEADERS)
@@ -198,6 +210,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
198210

199211
# These settings can be used by the test targets
200212
set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
213+
set(Casablanca_SYSTEM_INCLUDE_DIRS)
201214
if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
202215
find_path(WEBSOCKETPP_CONFIG websocketpp-config.cmake
203216
HINTS /usr/lib/cmake/websocketpp)
@@ -207,15 +220,15 @@ if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
207220
include(${WEBSOCKETPP_CONFIG}/websocketpp-config.cmake)
208221
include(${WEBSOCKETPP_CONFIG}/websocketpp-configVersion.cmake)
209222
message("-- Found websocketpp version " ${PACKAGE_VERSION} " on system")
210-
set(Casablanca_SYSTEM_INCLUDE_DIRS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${WEBSOCKETPP_INCLUDE_DIR})
223+
list(APPEND Casablanca_SYSTEM_INCLUDE_DIRS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${WEBSOCKETPP_INCLUDE_DIR})
211224
else(WEBSOCKETPP_CONFIG AND WEBSOCKETPP_CONFIG_VERSION)
212-
set(Casablanca_SYSTEM_INCLUDE_DIRS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libs/websocketpp)
225+
list(APPEND Casablanca_SYSTEM_INCLUDE_DIRS ${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libs/websocketpp)
213226
message("-- websocketpp not found, using the embedded version")
214227
endif(WEBSOCKETPP_CONFIG AND WEBSOCKETPP_CONFIG_VERSION)
215228
endif()
216229

217230
set(Casablanca_LIBRARY cpprest)
218-
set(Casablanca_LIBRARIES cpprest ${Boost_LIBRARIES})
231+
set(Casablanca_LIBRARIES cpprest ${Boost_LIBRARIES} ${ZLIB_LIBRARIES})
219232
set(Casablanca_LIBRARIES ${Casablanca_LIBRARIES} PARENT_SCOPE)
220233

221234
# Everything in the project needs access to the casablanca include directories

Release/include/cpprest/details/http_helpers.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@
2929

3030
#include "cpprest/details/basic_types.h"
3131

32+
#if __APPLE__
33+
#include "TargetConditionals.h"
34+
#endif
35+
36+
// CPPREST_EXCLUDE_COMPRESSION is set if we're on a platform that supports compression but we want to explicitly disable it.
37+
// CPPREST_EXCLUDE_WEBSOCKETS is a flag that now essentially means "no external dependencies". TODO: Rename
38+
#if (defined(_WIN32) || defined(TARGET_OS_MAC)) && !defined(CPPREST_EXCLUDE_WEBSOCKETS) && !defined(CPPREST_EXCLUDE_COMPRESSION)
39+
#define CPPREST_HTTP_COMPRESSION
40+
#endif
41+
42+
#include "cpprest/http_msg.h"
43+
3244
namespace web { namespace http
3345
{
3446
namespace details
@@ -61,4 +73,82 @@ namespace details
6173
_ASYNCRTIMP size_t __cdecl add_chunked_delimiters(_Out_writes_(buffer_size) uint8_t *data, _In_ size_t buffer_size, size_t bytes_read);
6274
}
6375

76+
namespace compression
77+
{
78+
enum class compression_algorithm : int
79+
{
80+
deflate = 15,
81+
gzip = 31,
82+
invalid = 9999
83+
};
84+
85+
using data_buffer = std::vector<uint8_t>;
86+
87+
class stream_decompressor
88+
{
89+
public:
90+
91+
static compression_algorithm to_compression_algorithm(const utility::string_t& alg)
92+
{
93+
if (U("gzip") == alg)
94+
{
95+
return compression_algorithm::gzip;
96+
}
97+
else if (U("deflate") == alg)
98+
{
99+
return compression_algorithm::deflate;
100+
}
101+
102+
return compression_algorithm::invalid;
103+
}
104+
105+
static bool is_supported()
106+
{
107+
#if !defined(CPPREST_HTTP_COMPRESSION)
108+
return false;
109+
#else
110+
return true;
111+
#endif
112+
}
113+
114+
_ASYNCRTIMP stream_decompressor(compression_algorithm alg);
115+
116+
_ASYNCRTIMP data_buffer decompress(const data_buffer& input);
117+
118+
_ASYNCRTIMP data_buffer decompress(const uint8_t* input, size_t input_size);
119+
120+
_ASYNCRTIMP bool has_error() const;
121+
122+
private:
123+
class stream_decompressor_impl;
124+
std::shared_ptr<stream_decompressor_impl> m_pimpl;
125+
};
126+
127+
class stream_compressor
128+
{
129+
public:
130+
131+
static bool is_supported()
132+
{
133+
#if !defined(CPPREST_HTTP_COMPRESSION)
134+
return false;
135+
#else
136+
return true;
137+
#endif
138+
}
139+
140+
_ASYNCRTIMP stream_compressor(compression_algorithm alg);
141+
142+
_ASYNCRTIMP data_buffer compress(const data_buffer& input, bool finish);
143+
144+
_ASYNCRTIMP data_buffer compress(const uint8_t* input, size_t input_size, bool finish);
145+
146+
_ASYNCRTIMP bool has_error() const;
147+
148+
private:
149+
class stream_compressor_impl;
150+
std::shared_ptr<stream_compressor_impl> m_pimpl;
151+
};
152+
153+
}
64154
}}}

Release/include/cpprest/http_client.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class http_client_config
9494
http_client_config() :
9595
m_guarantee_order(false),
9696
m_timeout(std::chrono::seconds(30)),
97-
m_chunksize(0)
97+
m_chunksize(0),
98+
m_request_compressed(false)
9899
#if !defined(__cplusplus_winrt)
99100
, m_validate_certificates(true)
100101
#endif
@@ -258,6 +259,27 @@ class http_client_config
258259
return m_chunksize == 0;
259260
}
260261

262+
/// <summary>
263+
/// Checks if requesting a compressed response is turned on, the default is off.
264+
/// </summary>
265+
/// <returns>True if compressed response is enabled, false otherwise</returns>
266+
bool request_compressed_response() const
267+
{
268+
return m_request_compressed;
269+
}
270+
271+
/// <summary>
272+
/// Request that the server responds with a compressed body.
273+
/// If true, in cases where the server does not support compression, this will have no effect.
274+
/// The response body is internally decompressed before the consumer receives the data.
275+
/// </summary>
276+
/// <param name="request_compressed">True to turn on response body compression, false otherwise.</param>
277+
/// <remarks>Please note there is a performance cost due to copying the request data. Currently only supported on Windows and OSX.</remarks>
278+
void set_request_compressed_response(bool request_compressed)
279+
{
280+
m_request_compressed = request_compressed;
281+
}
282+
261283
#if !defined(__cplusplus_winrt)
262284
/// <summary>
263285
/// Gets the server certificate validation property.
@@ -379,6 +401,7 @@ class http_client_config
379401

380402
std::chrono::microseconds m_timeout;
381403
size_t m_chunksize;
404+
bool m_request_compressed;
382405

383406
#if !defined(__cplusplus_winrt)
384407
// IXmlHttpRequest2 doesn't allow configuration of certificate verification.

Release/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ target_link_libraries(cpprest
128128
${OPENSSL_LIBRARIES}
129129
${COREFOUNDATION}
130130
${ANDROID_STL_FLAGS}
131+
${ZLIB_LIBRARIES}
131132
)
132133

133134
# Portions specific to cpprest binary versioning.

Release/src/build/vs14.wod/casablanca140.wod.vcxproj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@
2121
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))\Build\Release.Product.Settings" />
2222
<ImportGroup Label="PropertySheets">
2323
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
24+
<Import Project="..\..\..\..\packages\zlib.v140.windesktop.msvcstl.static.rt-dyn.1.2.8.8\build\native\zlib.v140.windesktop.msvcstl.static.rt-dyn.targets" Condition="Exists('..\..\..\..\packages\zlib.v140.windesktop.msvcstl.static.rt-dyn.1.2.8.8\build\native\zlib.v140.windesktop.msvcstl.static.rt-dyn.targets')" />
2425
</ImportGroup>
2526
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
2627
<DebugFileSuffix>d</DebugFileSuffix>
2728
</PropertyGroup>
2829
<PropertyGroup>
2930
<TargetName>$(CppRestBaseFileName)140$(DebugFileSuffix)_$(CppRestSDKVersionFileSuffix).wod</TargetName>
30-
<NuGetPackageImportStamp>57c5697d</NuGetPackageImportStamp>
3131
</PropertyGroup>
32+
<ItemGroup>
33+
<None Include="packages.config" />
34+
</ItemGroup>
3235
<ItemDefinitionGroup>
3336
<ClCompile>
3437
<PreprocessorDefinitions>CPPREST_EXCLUDE_WEBSOCKETS;_ASYNCRT_EXPORT;_PPLX_EXPORT;WIN32;_MBCS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -47,4 +50,10 @@
4750
<Import Project="..\common.vcxitems" Label="Shared" Condition="Exists('..\common.vcxitems')" />
4851
<Import Project="..\win32.vcxitems" Label="Shared" Condition="Exists('..\win32.vcxitems')" />
4952
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
53+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
54+
<PropertyGroup>
55+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
56+
</PropertyGroup>
57+
<Error Condition="!Exists('..\..\..\..\packages\zlib.v140.windesktop.msvcstl.static.rt-dyn.1.2.8.8\build\native\zlib.v140.windesktop.msvcstl.static.rt-dyn.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\zlib.v140.windesktop.msvcstl.static.rt-dyn.1.2.8.8\build\native\zlib.v140.windesktop.msvcstl.static.rt-dyn.targets'))" />
58+
</Target>
5059
</Project>

0 commit comments

Comments
 (0)