Skip to content

Commit 6388246

Browse files
Support CURL based HTTP client
1 parent 5b32e16 commit 6388246

File tree

11 files changed

+6648
-13
lines changed

11 files changed

+6648
-13
lines changed

Release/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ endif()
6161

6262
include(cmake/cpprest_find_boost.cmake)
6363
include(cmake/cpprest_find_zlib.cmake)
64+
include(cmake/cpprest_find_curl.cmake)
6465
include(cmake/cpprest_find_openssl.cmake)
6566
include(cmake/cpprest_find_websocketpp.cmake)
6667
include(cmake/cpprest_find_brotli.cmake)
@@ -164,7 +165,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR IOS)
164165
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
165166
message("-- Setting gcc options")
166167

167-
set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code)
168+
set(WARNINGS -Wall -Wextra -Wunused-parameter -Wcast-align -Wcast-qual -Wconversion -Wformat=2 -Winit-self -Winvalid-pch -Wmissing-format-attribute -Wno-unused-parameter -Wmissing-include-dirs -Wpacked -Wredundant-decls -Wunreachable-code)
168169
set(LD_FLAGS "${LD_FLAGS} -Wl,-z,defs")
169170

170171
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-strict-aliasing")

Release/cmake/cpprest_find_curl.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function(cpprest_find_curl)
2+
if(TARGET cpprestsdk_curl_internal)
3+
return()
4+
endif()
5+
6+
if(NOT CURL_LIBRARY OR NOT CURL_INCLUDE_DIRS)
7+
find_package(CURL REQUIRED)
8+
endif()
9+
10+
add_library(cpprestsdk_curl_internal INTERFACE)
11+
if(TARGET CURL::CURL)
12+
target_link_libraries(cpprestsdk_curl_internal INTERFACE CURL::CURL)
13+
else()
14+
target_link_libraries(cpprestsdk_curl_internal INTERFACE "$<BUILD_INTERFACE:${CURL_LIBRARY}>")
15+
target_include_directories(cpprestsdk_curl_internal INTERFACE "$<BUILD_INTERFACE:${CURL_INCLUDE_DIRS}>")
16+
endif()
17+
endfunction()

Release/cmake/cpprestsdk-config.in.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ if(@CPPREST_USES_OPENSSL@)
1111
find_dependency(OpenSSL)
1212
endif()
1313

14+
if(@CPPREST_USES_CURL@)
15+
find_dependency(CURL)
16+
endif()
17+
1418
if(@CPPREST_USES_BOOST@ AND OFF)
1519
if(UNIX)
1620
find_dependency(Boost COMPONENTS random system thread filesystem chrono atomic date_time regex)

Release/include/cpprest/http_client.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ class http_client_config
104104
#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO)
105105
, m_tlsext_sni_enabled(true)
106106
#endif
107-
#if defined(_WIN32) && !defined(__cplusplus_winrt)
108107
, m_buffer_request(false)
109-
#endif
110108
{
111109
}
112110

@@ -262,7 +260,6 @@ class http_client_config
262260
void set_validate_certificates(bool validate_certs) { m_validate_certificates = validate_certs; }
263261
#endif
264262

265-
#if defined(_WIN32) && !defined(__cplusplus_winrt)
266263
/// <summary>
267264
/// Checks if request data buffering is turned on, the default is off.
268265
/// </summary>
@@ -277,7 +274,6 @@ class http_client_config
277274
/// <param name="buffer_request">True to turn on buffer, false otherwise.</param>
278275
/// <remarks>Please note there is a performance cost due to copying the request data.</remarks>
279276
void set_buffer_request(bool buffer_request) { m_buffer_request = buffer_request; }
280-
#endif
281277

282278
/// <summary>
283279
/// Sets a callback to enable custom setting of platform specific options.
@@ -389,9 +385,7 @@ class http_client_config
389385
std::function<void(boost::asio::ssl::context&)> m_ssl_context_callback;
390386
bool m_tlsext_sni_enabled;
391387
#endif
392-
#if defined(_WIN32) && !defined(__cplusplus_winrt)
393388
bool m_buffer_request;
394-
#endif
395389
};
396390

397391
class http_pipeline;

Release/src/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ if(CPPREST_HTTP_CLIENT_IMPL STREQUAL "asio")
131131
target_compile_definitions(cpprest PUBLIC -DCPPREST_FORCE_HTTP_CLIENT_ASIO)
132132
target_sources(cpprest PRIVATE http/client/http_client_asio.cpp http/client/x509_cert_utilities.cpp)
133133
target_link_libraries(cpprest PUBLIC cpprestsdk_boost_internal cpprestsdk_openssl_internal)
134+
elseif(CPPREST_HTTP_CLIENT_IMPL STREQUAL "curl")
135+
cpprest_find_boost()
136+
cpprest_find_openssl()
137+
cpprest_find_curl()
138+
target_compile_definitions(cpprest PUBLIC -DCPPREST_FORCE_HTTP_CLIENT_CURL)
139+
target_sources(cpprest PRIVATE http/client/http_client_curl.cpp http/client/winhttppal/winhttppal.cpp http/client/x509_cert_utilities.cpp)
140+
target_link_libraries(cpprest PUBLIC cpprestsdk_boost_internal cpprestsdk_openssl_internal cpprestsdk_curl_internal)
134141
elseif(CPPREST_HTTP_CLIENT_IMPL STREQUAL "winhttp")
135142
target_link_libraries(cpprest PRIVATE
136143
httpapi.lib
@@ -248,6 +255,7 @@ if(CPPREST_INSTALL)
248255
set(CPPREST_USES_ZLIB OFF)
249256
set(CPPREST_USES_BROTLI OFF)
250257
set(CPPREST_USES_OPENSSL OFF)
258+
set(CPPREST_USES_CURL OFF)
251259

252260
set(CPPREST_TARGETS cpprest)
253261
if(TARGET cpprestsdk_boost_internal)
@@ -266,6 +274,10 @@ if(CPPREST_INSTALL)
266274
list(APPEND CPPREST_TARGETS cpprestsdk_openssl_internal)
267275
set(CPPREST_USES_OPENSSL ON)
268276
endif()
277+
if(TARGET cpprestsdk_curl_internal)
278+
list(APPEND CPPREST_TARGETS cpprestsdk_curl_internal)
279+
set(CPPREST_USES_CURL ON)
280+
endif()
269281
if(TARGET cpprestsdk_websocketpp_internal)
270282
list(APPEND CPPREST_TARGETS cpprestsdk_websocketpp_internal)
271283
endif()

0 commit comments

Comments
 (0)