Support chunked response content (but no Trailer headers).

This commit is contained in:
Chunting Gu
2019-01-31 18:10:12 +08:00
parent 01c7a6e328
commit 8d9855f751
11 changed files with 290 additions and 97 deletions
+15
View File
@@ -0,0 +1,15 @@
set(LIBS webcc jsoncpp ${Boost_LIBRARIES} "${CMAKE_THREAD_LIBS_INIT}")
set(LIBS ${LIBS} ${OPENSSL_LIBRARIES})
if(WIN32)
set(LIBS ${LIBS} crypt32)
endif()
if(UNIX)
# Add `-ldl` for Linux to avoid "undefined reference to `dlopen'".
set(LIBS ${LIBS} ${CMAKE_DL_LIBS})
endif()
add_executable(github_rest_client main.cc)
target_link_libraries(github_rest_client ${LIBS})
+25 -13
View File
@@ -3,19 +3,37 @@
#include "webcc/http_ssl_client.h"
#include "webcc/logger.h"
void Test() {
int main(int argc, char* argv[]) {
std::string host;
std::string url;
if (argc != 3) {
host = "www.boost.org";
url = "/LICENSE_1_0.txt";
} else {
host = argv[1];
url = argv[2];
}
std::cout << "Host: " << host << std::endl;
std::cout << "URL: " << url << std::endl;
std::cout << std::endl;
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
webcc::HttpRequest request;
request.set_method(webcc::kHttpGet);
request.set_url("/LICENSE_1_0.txt");
// Leave port to default value.
request.set_host("www.boost.org");
request.set_url(url);
request.set_host(host); // Leave port to default value.
request.Make();
webcc::HttpSslClient client;
if (client.Request(request)) {
// Verify the certificate of the peer or not.
// See HttpSslClient::Request() for more details.
bool ssl_verify = false;
if (client.Request(request, ssl_verify)) {
std::cout << client.response()->content() << std::endl;
} else {
std::cout << webcc::DescribeError(client.error());
@@ -24,12 +42,6 @@ void Test() {
}
std::cout << std::endl;
}
}
int main() {
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
Test();
return 0;
}
-10
View File
@@ -1,10 +0,0 @@
add_executable(rest_github_client main.cc)
set(SSL_LIBS ${OPENSSL_LIBRARIES})
if(WIN32)
set(SSL_LIBS ${SSL_LIBS} crypt32)
endif()
target_link_libraries(rest_github_client webcc jsoncpp ${Boost_LIBRARIES})
target_link_libraries(rest_github_client "${CMAKE_THREAD_LIBS_INIT}")
target_link_libraries(rest_github_client ${SSL_LIBS})