fix ssl handshake and parsing issues
This commit is contained in:
+19
-15
@@ -9,33 +9,37 @@ if(UNIX)
|
||||
endif()
|
||||
|
||||
set(SIMPLE_EXAMPLES
|
||||
concurrency_test
|
||||
client_basics
|
||||
hello_world_server
|
||||
static_file_server
|
||||
file_downloader
|
||||
server_states
|
||||
form_client
|
||||
form_server
|
||||
form_urlencoded_client
|
||||
)
|
||||
concurrency_test
|
||||
client_basics
|
||||
hello_world_server
|
||||
static_file_server
|
||||
file_downloader
|
||||
server_states
|
||||
form_client
|
||||
form_server
|
||||
form_urlencoded_client
|
||||
)
|
||||
|
||||
foreach(example ${SIMPLE_EXAMPLES})
|
||||
add_executable(${example} ${example}.cc)
|
||||
target_link_libraries(${example} ${EXAMPLE_LIBS})
|
||||
set_target_properties(${example} PROPERTIES FOLDER "Examples")
|
||||
add_executable(${example} ${example}.cc)
|
||||
target_link_libraries(${example} ${EXAMPLE_LIBS})
|
||||
set_target_properties(${example} PROPERTIES FOLDER "Examples")
|
||||
endforeach()
|
||||
|
||||
if(WEBCC_ENABLE_SSL)
|
||||
add_executable(github_client github_client.cc)
|
||||
target_link_libraries(github_client ${EXAMPLE_LIBS} jsoncpp)
|
||||
set_target_properties(github_client PROPERTIES FOLDER "Examples")
|
||||
set_target_properties(github_client PROPERTIES FOLDER "Examples")
|
||||
|
||||
add_executable(google_client google_client.cc)
|
||||
target_link_libraries(google_client ${EXAMPLE_LIBS})
|
||||
set_target_properties(google_client PROPERTIES FOLDER "Examples")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_executable(url_unicode url_unicode.cc encoding.cc encoding.h)
|
||||
target_link_libraries(url_unicode ${EXAMPLE_LIBS})
|
||||
set_target_properties(url_unicode PROPERTIES FOLDER "Examples")
|
||||
set_target_properties(url_unicode PROPERTIES FOLDER "Examples")
|
||||
endif()
|
||||
|
||||
add_subdirectory(book_server)
|
||||
|
||||
@@ -15,27 +15,24 @@ int main() {
|
||||
webcc::ResponsePtr r;
|
||||
|
||||
try {
|
||||
r = session.Send(webcc::RequestBuilder{}.
|
||||
Get("http://httpbin.org/get").
|
||||
Query("name", "Adam Gu", /*encode*/true).Date()
|
||||
());
|
||||
r = session.Send(WEBCC_GET("http://httpbin.org/get")
|
||||
.Query("name", "Adam Gu", true)
|
||||
.Date()());
|
||||
|
||||
assert(r->status() == webcc::Status::kOK);
|
||||
assert(!r->data().empty());
|
||||
|
||||
r = session.Send(webcc::RequestBuilder{}.
|
||||
Post("http://httpbin.org/post").
|
||||
Body("{'name'='Adam', 'age'=20}").Json().Utf8()
|
||||
());
|
||||
r = session.Send(WEBCC_POST("http://httpbin.org/post")
|
||||
.Body("{'name'='Adam', 'age'=20}")
|
||||
.Json()
|
||||
.Utf8()());
|
||||
|
||||
assert(r->status() == webcc::Status::kOK);
|
||||
assert(!r->data().empty());
|
||||
|
||||
#if WEBCC_ENABLE_SSL
|
||||
|
||||
r = session.Send(webcc::RequestBuilder{}.
|
||||
Get("https://httpbin.org/get")
|
||||
());
|
||||
r = session.Send(WEBCC_GET("https://httpbin.org/get")());
|
||||
|
||||
assert(r->status() == webcc::Status::kOK);
|
||||
assert(!r->data().empty());
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// google_client.cc
|
||||
// This example sends a GET request to https://www.google.com/.
|
||||
|
||||
// NOTE:
|
||||
// - The response body is chunked
|
||||
// - The Google server requires the client to call `SSL_set_tlsext_host_name()`
|
||||
// or the SSL handshake would fail. This is different from other HTTPS servers
|
||||
// like api.github.com or httpbin.org.
|
||||
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
#include "webcc/client_session.h"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
int main() {
|
||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||
|
||||
webcc::ClientSession session;
|
||||
|
||||
try {
|
||||
auto r = session.Send(WEBCC_GET("https://www.google.com/")());
|
||||
|
||||
std::cout << std::endl;
|
||||
std::cout << r->status() << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cout << r->data() << std::endl;
|
||||
|
||||
} catch (const webcc::Error& error) {
|
||||
std::cerr << error << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user