Compare commits

..

20 Commits

Author SHA1 Message Date
yhirose
d7e63b4316 Update README 2020-08-16 20:49:54 -04:00
yhirose
e5dd410256 Added set_content_provider without content length 2020-08-15 05:53:49 -04:00
yhirose
951e46929e Fix #609 2020-08-14 15:01:09 -04:00
yhirose
c8adac30f4 Fix #564 again 2020-08-13 08:07:25 -04:00
yhirose
b2b4f7635f Fix #608 2020-08-11 12:11:05 -04:00
R Edgar
649b1d2172 Fix nullptr_t issue (#605)
Clang complains that `nullptr_t` should be `std::nullptr_t
2020-08-09 16:45:53 -04:00
yhirose
dc5f9ba164 Better error handling on client (#601) 2020-08-08 20:50:24 -04:00
yhirose
cf084e1db1 Fixed example build errors 2020-08-08 00:10:08 -04:00
KTGH
e0e5898601 Overhaul FindBrotli to fix weird issues (#604)
Should get rid of the issue about not being able to create an ALIAS on
MinGW, as well as the "No REQUIRED_VARS" issue.

Fixes #603 (hopefully)
2020-08-06 07:08:29 -04:00
yhirose
dfec2de5b5 Update README 2020-08-03 23:37:05 -04:00
yhirose
04002d57bd Added set_default_headers (Fix #600) 2020-08-03 22:05:37 -04:00
yhirose
38a7706c8b Removed old Keep-Alive functions 2020-08-03 22:04:40 -04:00
KTGH
abaf875c42 Fix FindBrotli when no Brotli installed (#598)
Woops.

Ref https://github.com/yhirose/cpp-httplib/issues/582#issuecomment-667537002
2020-08-01 17:08:49 -04:00
PixlRainbow
5f76cb01c7 fix #592 -- add check for static-linked OpenSSL (#595) 2020-08-01 08:10:42 -04:00
yhirose
ae54e833ea Code cleanup 2020-07-31 23:48:42 -04:00
yhirose
0dd3659de5 Updated README 2020-07-31 18:54:53 -04:00
KTGH
999f6abd2c Fix for Cmake on systems without Git (#594)
If you didn't have Git installed, execute_process never declared the
error variable, which led to it never parsing the header for a version.
So if Git wasn't installed, the version variable never got declared,
which caused errors.

This fixes that.
2020-07-31 13:46:12 -04:00
KTGH
48da75dd35 Fix FindBrotli for static libs (#593)
It wasn't linking them.
2020-07-31 13:45:21 -04:00
yhirose
4f84eeb298 Bearer Token auth support. Fix #484 2020-07-31 12:37:14 -04:00
yhirose
a5b4cfadb9 Brotli suport on server. Fix #578 2020-07-31 10:23:57 -04:00
9 changed files with 1409 additions and 1027 deletions

View File

@@ -1,6 +1,6 @@
#[[ #[[
Build options: Build options:
* BUILD_SHARED_LIBS (default off) builds as a static library (if HTTPLIB_COMPILE is ON) * BUILD_SHARED_LIBS (default off) builds as a shared library (if HTTPLIB_COMPILE is ON)
* HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on) * HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on)
* HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on) * HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on)
* HTTPLIB_REQUIRE_OPENSSL (default off) * HTTPLIB_REQUIRE_OPENSSL (default off)
@@ -60,17 +60,21 @@
]] ]]
cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
# Gets the latest tag as a string like "v0.6.6" # On systems without Git installed, there were errors since execute_process seemed to not throw an error without it?
# Can silently fail if git isn't on the system find_package(Git QUIET)
execute_process(COMMAND git describe --tags --abbrev=0 if(Git_FOUND)
OUTPUT_VARIABLE _raw_version_string # Gets the latest tag as a string like "v0.6.6"
ERROR_VARIABLE _git_tag_error # Can silently fail if git isn't on the system
) execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
OUTPUT_VARIABLE _raw_version_string
ERROR_VARIABLE _git_tag_error
)
endif()
# execute_process can fail silenty, so check for an error # execute_process can fail silenty, so check for an error
# if there was an error, just use the user agent as a version # if there was an error, just use the user agent as a version
if(_git_tag_error) if(_git_tag_error OR NOT Git_FOUND)
message(WARNING "cpp-httplib failed to find the latest git tag, falling back to using user agent as the version.") message(WARNING "cpp-httplib failed to find the latest Git tag, falling back to using user agent as the version.")
# Get the user agent and use it as a version # Get the user agent and use it as a version
# This gets the string with the user agent from the header. # This gets the string with the user agent from the header.
# This is so the maintainer doesn't actually need to update this manually. # This is so the maintainer doesn't actually need to update this manually.
@@ -101,7 +105,7 @@ if(HTTPLIB_COMPILE)
endif() endif()
option(HTTPLIB_REQUIRE_BROTLI "Requires Brotli to be found & linked, or fails build." OFF) option(HTTPLIB_REQUIRE_BROTLI "Requires Brotli to be found & linked, or fails build." OFF)
option(HTTPLIB_USE_BROTLI_IF_AVAILABLE "Uses Brotli (if available) to enable Brotli compression support." ON) option(HTTPLIB_USE_BROTLI_IF_AVAILABLE "Uses Brotli (if available) to enable Brotli decompression support." ON)
# Defaults to static library # Defaults to static library
option(BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF) option(BUILD_SHARED_LIBS "Build the library as a shared library instead of static. Has no effect if using header-only." OFF)
if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE) if (BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE)

View File

@@ -175,6 +175,7 @@ svr.Get("/stream", [&](const Request &req, Response &res) {
res.set_content_provider( res.set_content_provider(
data->size(), // Content length data->size(), // Content length
"text/plain", // Content type
[data](size_t offset, size_t length, DataSink &sink) { [data](size_t offset, size_t length, DataSink &sink) {
const auto &d = *data; const auto &d = *data;
sink.write(&d[offset], std::min(length, DATA_CHUNK_SIZE)); sink.write(&d[offset], std::min(length, DATA_CHUNK_SIZE));
@@ -184,6 +185,25 @@ svr.Get("/stream", [&](const Request &req, Response &res) {
}); });
``` ```
Without content length:
```cpp
svr.Get("/stream", [&](const Request &req, Response &res) {
res.set_content_provider(
"text/plain", // Content type
[&](size_t offset, size_t length, DataSink &sink) {
if (/* there is still data */) {
std::vector<char> data;
// prepare data...
sink.write(data.data(), data.size());
} else {
done(); // No more data
}
return true; // return 'false' if you want to cancel the process.
});
});
```
### Chunked transfer encoding ### Chunked transfer encoding
```cpp ```cpp
@@ -193,7 +213,7 @@ svr.Get("/chunked", [&](const Request& req, Response& res) {
sink.write("123", 3); sink.write("123", 3);
sink.write("345", 3); sink.write("345", 3);
sink.write("789", 3); sink.write("789", 3);
sink.done(); sink.done(); // No more data
return true; // return 'false' if you want to cancel the process. return true; // return 'false' if you want to cancel the process.
} }
); );
@@ -286,9 +306,13 @@ int main(void)
{ {
httplib::Client cli("localhost", 1234); httplib::Client cli("localhost", 1234);
auto res = cli.Get("/hi"); if (auto res = cli.Get("/hi")) {
if (res && res->status == 200) { if (res->status == 200) {
std::cout << res->body << std::endl; std::cout << res->body << std::endl;
}
} else {
auto err = res.error();
...
} }
} }
``` ```
@@ -311,6 +335,13 @@ httplib::Headers headers = {
}; };
auto res = cli.Get("/hi", headers); auto res = cli.Get("/hi", headers);
``` ```
or
```c++
cli.set_default_headers({
{ "Accept-Encoding", "gzip, deflate" }
});
auto res = cli.Get("/hi");
```
### POST ### POST
@@ -427,13 +458,12 @@ auto res = cli_.Post(
httplib::Client client(url, port); httplib::Client client(url, port);
// prints: 0 / 000 bytes => 50% complete // prints: 0 / 000 bytes => 50% complete
std::shared_ptr<httplib::Response> res = auto res = cli.Get("/", [](uint64_t len, uint64_t total) {
cli.Get("/", [](uint64_t len, uint64_t total) { printf("%lld / %lld bytes => %d%% complete\n",
printf("%lld / %lld bytes => %d%% complete\n", len, total,
len, total, (int)(len*100/total));
(int)(len*100/total)); return true; // return 'false' if you want to cancel the request.
return true; // return 'false' if you want to cancel the request. }
}
); );
``` ```
@@ -447,6 +477,9 @@ cli.set_basic_auth("user", "pass");
// Digest Authentication // Digest Authentication
cli.set_digest_auth("user", "pass"); cli.set_digest_auth("user", "pass");
// Bearer Token Authentication
cli.set_bearer_token_auth("token");
``` ```
NOTE: OpenSSL is required for Digest Authentication. NOTE: OpenSSL is required for Digest Authentication.
@@ -461,6 +494,9 @@ cli.set_proxy_basic_auth("user", "pass");
// Digest Authentication // Digest Authentication
cli.set_proxy_digest_auth("user", "pass"); cli.set_proxy_digest_auth("user", "pass");
// Bearer Token Authentication
cli.set_proxy_bearer_token_auth("pass");
``` ```
NOTE: OpenSSL is required for Digest Authentication. NOTE: OpenSSL is required for Digest Authentication.

View File

@@ -5,181 +5,174 @@
# The targets will have the same names, but it will use the static libs. # The targets will have the same names, but it will use the static libs.
# #
# Valid find_package COMPONENTS names: "decoder", "encoder", and "common" # Valid find_package COMPONENTS names: "decoder", "encoder", and "common"
# Note that if you're requiring "decoder" or "encoder", then "common" will be automatically added as required.
# #
# Defines the libraries (if found): Brotli::decoder, Brotli::encoder, Brotli::common # Defines the libraries (if found): Brotli::decoder, Brotli::encoder, Brotli::common
# and the includes path variable: Brotli_INCLUDE_DIR # and the includes path variable: Brotli_INCLUDE_DIR
#
# If it's failing to find the libraries, try setting BROTLI_ROOT_DIR to the folder containing your library & include dir.
function(brotli_err_msg _err_msg) # If they asked for a specific version, warn/fail since we don't support it.
# TODO: if they start distributing the version somewhere, implement finding it.
# But currently there's a version header that doesn't seem to get installed.
if(Brotli_FIND_VERSION)
set(_brotli_version_error_msg "FindBrotli.cmake doesn't have version support!")
# If the package is required, throw a fatal error # If the package is required, throw a fatal error
# Otherwise, if not running quietly, we throw a warning # Otherwise, if not running quietly, we throw a warning
if(Brotli_FIND_REQUIRED) if(Brotli_FIND_REQUIRED)
message(FATAL_ERROR "${_err_msg}") message(FATAL_ERROR "${_brotli_version_error_msg}")
elseif(NOT Brotli_FIND_QUIETLY) elseif(NOT Brotli_FIND_QUIETLY)
message(WARNING "${_err_msg}") message(WARNING "${_brotli_version_error_msg}")
endif() endif()
endfunction()
# If they asked for a specific version, warn/fail since we don't support it.
if(Brotli_FIND_VERSION)
brotli_err_msg("FindBrotli.cmake doesn't have version support!")
endif() endif()
# Since both decoder & encoder require the common lib (I think), force its requirement.. # Since both decoder & encoder require the common lib, force its requirement..
# if the user is requiring either of those other libs. # if the user is requiring either of those other libs.
if(Brotli_FIND_REQUIRED_decoder OR Brotli_FIND_REQUIRED_encoder) if(Brotli_FIND_REQUIRED_decoder OR Brotli_FIND_REQUIRED_encoder)
set(Brotli_FIND_REQUIRED_common TRUE) set(Brotli_FIND_REQUIRED_common TRUE)
endif() endif()
# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES
# Credit to FindOpenSSL.cmake for this
if(BROTLI_USE_STATIC_LIBS)
set(_brotli_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
if(WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
endif()
endif()
# Make PkgConfig optional, since some users (mainly Windows) don't have it. # Make PkgConfig optional, since some users (mainly Windows) don't have it.
# But it's a lot more clean than manually using find_library. # But it's a lot more clean than manually using find_library.
find_package(PkgConfig QUIET) find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
if(BROTLI_USE_STATIC_LIBS)
pkg_check_modules(Brotli_common_STATIC QUIET IMPORTED_TARGET libbrotlicommon)
pkg_check_modules(Brotli_decoder_STATIC QUIET IMPORTED_TARGET libbrotlidec)
pkg_check_modules(Brotli_encoder_STATIC QUIET IMPORTED_TARGET libbrotlienc)
else()
pkg_check_modules(Brotli_common QUIET IMPORTED_TARGET libbrotlicommon)
pkg_check_modules(Brotli_decoder QUIET IMPORTED_TARGET libbrotlidec)
pkg_check_modules(Brotli_encoder QUIET IMPORTED_TARGET libbrotlienc)
endif()
endif()
# Only used if the PkgConfig libraries aren't used. # Only used if the PkgConfig libraries aren't used.
find_path(Brotli_INCLUDE_DIR find_path(Brotli_INCLUDE_DIR
NAMES "brotli/decode.h" "brotli/encode.h" NAMES
PATH_SUFFIXES "include" "includes" "brotli/decode.h"
"brotli/encode.h"
HINTS
${BROTLI_ROOT_DIR}
PATH_SUFFIXES
"include"
"includes"
DOC "The path to Brotli's include directory." DOC "The path to Brotli's include directory."
) )
# Hides this var from the GUI
mark_as_advanced(Brotli_INCLUDE_DIR)
# Also check if Brotli_decoder was defined, as it can be passed by the end-user # Just used for PkgConfig stuff in the loop below
if(NOT TARGET PkgConfig::Brotli_decoder AND NOT Brotli_decoder) set(_brotli_stat_str "")
if(BROTLI_USE_STATIC_LIBS) if(BROTLI_USE_STATIC_LIBS)
list(APPEND _brotli_decoder_lib_names set(_brotli_stat_str "_STATIC")
"brotlidec-static"
"libbrotlidec-static"
)
else()
list(APPEND _brotli_decoder_lib_names
"brotlidec"
"libbrotlidec"
)
endif()
find_library(Brotli_decoder
NAMES ${_brotli_decoder_lib_names}
PATH_SUFFIXES
"lib"
"lib64"
"libs"
"libs64"
"lib/x86_64-linux-gnu"
)
endif() endif()
# Also check if Brotli_encoder was defined, as it can be passed by the end-user # Lets us know we are using the PkgConfig libraries
if(NOT TARGET PkgConfig::Brotli_encoder AND NOT Brotli_encoder) # Will be set false if any non-pkgconf vars are used
if(BROTLI_USE_STATIC_LIBS) set(_brotli_using_pkgconf TRUE)
list(APPEND _brotli_encoder_lib_names
"brotlienc-static" # Each string here is "ComponentName;LiteralName" (the semi-colon is a delimiter)
"libbrotlienc-static" foreach(_listvar "common;common" "decoder;dec" "encoder;enc")
) # Split the component name and literal library name from the listvar
else() list(GET _listvar 0 _component_name)
list(APPEND _brotli_encoder_lib_names list(GET _listvar 1 _libname)
"brotlienc"
"libbrotlienc" if(PKG_CONFIG_FOUND)
) # These need to be GLOBAL for MinGW when making ALIAS libraries against them.
if(BROTLI_USE_STATIC_LIBS)
# Have to use _STATIC to tell PkgConfig to find the static libs.
pkg_check_modules(Brotli_${_component_name}_STATIC QUIET GLOBAL IMPORTED_TARGET libbrotli${_libname})
else()
pkg_check_modules(Brotli_${_component_name} QUIET GLOBAL IMPORTED_TARGET libbrotli${_libname})
endif()
endif() endif()
find_library(Brotli_encoder
NAMES ${_brotli_encoder_lib_names}
PATH_SUFFIXES
"lib"
"lib64"
"libs"
"libs64"
"lib/x86_64-linux-gnu"
)
endif()
# Also check if Brotli_common was defined, as it can be passed by the end-user # Check if the target was already found by Pkgconf
if(NOT TARGET PkgConfig::Brotli_common AND NOT Brotli_common) if(TARGET PkgConfig::Brotli_${_component_name} OR TARGET PkgConfig::Brotli_${_component_name}_STATIC)
if(BROTLI_USE_STATIC_LIBS) # Can't use generators for ALIAS targets, so you get this jank
list(APPEND _brotli_common_lib_names add_library(Brotli::${_component_name} ALIAS PkgConfig::Brotli_${_component_name}${_brotli_stat_str})
"brotlicommon-static"
"libbrotlicommon-static"
)
else()
list(APPEND _brotli_common_lib_names
"brotlicommon"
"libbrotlicommon"
)
endif()
find_library(Brotli_common
NAMES ${_brotli_common_lib_names}
PATH_SUFFIXES
"lib"
"lib64"
"libs"
"libs64"
"lib/x86_64-linux-gnu"
)
endif()
set(_brotli_req_vars "") # Tells HANDLE_COMPONENTS we found the component
# Generic loop to either create all the aliases for the end-user, or throw errors/warnings. set(Brotli_${_component_name}_FOUND TRUE)
# Note that the case here needs to match the case we used elsewhere in this file. if(Brotli_FIND_REQUIRED_${_component_name})
foreach(_target_name "common" "decoder" "encoder") # If the lib is required, we can add its literal path as a required var for FindPackageHandleStandardArgs
# The PkgConfig IMPORTED_TARGET has PkgConfig:: prefixed to it. # Since it won't accept the PkgConfig targets
if(TARGET PkgConfig::Brotli_${_target_name})
add_library(Brotli::${_target_name} ALIAS PkgConfig::Brotli_${_target_name})
if(Brotli_FIND_REQUIRED_${_target_name})
# The PkgConfig version of the library has a slightly different path to its lib.
if(BROTLI_USE_STATIC_LIBS) if(BROTLI_USE_STATIC_LIBS)
list(APPEND _brotli_req_vars "Brotli_${_target_name}_STATIC_LINK_LIBRARIES") list(APPEND _brotli_req_vars "Brotli_${_component_name}_STATIC_LIBRARIES")
else() else()
list(APPEND _brotli_req_vars "Brotli_${_target_name}_LINK_LIBRARIES") list(APPEND _brotli_req_vars "Brotli_${_component_name}_LINK_LIBRARIES")
endif() endif()
endif() endif()
# This will only trigger for libraries we found using find_library
elseif(Brotli_${_target_name}) # Skip searching for the libs with find_library since it was already found by Pkgconf
add_library("Brotli::${_target_name}" UNKNOWN IMPORTED) continue()
# Safety-check the includes dir endif()
if(NOT Brotli_INCLUDE_DIR)
brotli_err_msg("Failed to find Brotli's includes directory. Try manually defining \"Brotli_INCLUDE_DIR\" to Brotli's header path on your system.") # Lets us know we aren't using the PkgConfig libraries
endif() set(_brotli_using_pkgconf FALSE)
# Attach the literal library and include dir to the IMPORTED target for the end-user if(Brotli_FIND_REQUIRED_${_component_name})
set_target_properties("Brotli::${_target_name}" PROPERTIES # If it's required, we can set the name used in find_library as a required var for FindPackageHandleStandardArgs
INTERFACE_INCLUDE_DIRECTORIES "${Brotli_INCLUDE_DIR}" list(APPEND _brotli_req_vars "Brotli_${_component_name}")
IMPORTED_LOCATION "${Brotli_${_target_name}}" endif()
if(BROTLI_USE_STATIC_LIBS)
list(APPEND _brotli_lib_names
"brotli${_libname}-static"
"libbrotli${_libname}-static"
) )
# Attach the library from find_library to our required vars (if it's required) else()
if(Brotli_FIND_REQUIRED_${_target_name}) list(APPEND _brotli_lib_names
list(APPEND _brotli_req_vars "Brotli_${_target_name}") "brotli${_libname}"
endif() "libbrotli${_libname}"
# This will only happen if it's a required library but we didn't find it. )
elseif(Brotli_FIND_REQUIRED_${_target_name}) endif()
# Only bother with an error/failure if they actually required the lib.
brotli_err_msg("Failed to find Brotli's ${_target_name} library. Try manually defining \"Brotli_${_target_name}\" to its path on your system.") find_library(Brotli_${_component_name}
NAMES ${_brotli_lib_names}
HINTS ${BROTLI_ROOT_DIR}
PATH_SUFFIXES
"lib"
"lib64"
"libs"
"libs64"
"lib/x86_64-linux-gnu"
)
# Hide the library variable from the Cmake GUI
mark_as_advanced(Brotli_${_component_name})
# Unset since otherwise it'll stick around for the next loop and break things
unset(_brotli_lib_names)
# Check if find_library found the library
if(Brotli_${_component_name})
# Tells HANDLE_COMPONENTS we found the component
set(Brotli_${_component_name}_FOUND TRUE)
add_library("Brotli::${_component_name}" UNKNOWN IMPORTED)
# Attach the literal library and include dir to the IMPORTED target for the end-user
set_target_properties("Brotli::${_component_name}" PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Brotli_INCLUDE_DIR}"
IMPORTED_LOCATION "${Brotli_${_component_name}}"
)
else()
# Tells HANDLE_COMPONENTS we found the component
set(Brotli_${_component_name}_FOUND FALSE)
endif() endif()
endforeach() endforeach()
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
# Sets Brotli_FOUND, and fails the find_package(Brotli) call if it was REQUIRED but missing libs.
find_package_handle_standard_args(Brotli find_package_handle_standard_args(Brotli
FOUND_VAR Brotli_FOUND FOUND_VAR
REQUIRED_VARS ${_brotli_req_vars} Brotli_FOUND
REQUIRED_VARS
Brotli_INCLUDE_DIR
${_brotli_required_targets}
HANDLE_COMPONENTS
) )
if(Brotli_FOUND) # Restore the original find library ordering
include(FindPackageMessage) if(BROTLI_USE_STATIC_LIBS)
foreach(_lib_name ${_brotli_req_vars}) set(CMAKE_FIND_LIBRARY_SUFFIXES ${_brotli_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
# TODO: remove this if/when The Cmake PkgConfig file fixes the non-quiet message about libbrotlicommon being found.
if(${_lib_name} MATCHES "common")
# This avoids a duplicate "Found Brotli: /usr/lib/libbrotlicommon.so" type message.
continue()
endif()
# Double-expand the var to get the actual path instead of the variable's name.
find_package_message(Brotli "Found Brotli: ${${_lib_name}}"
"[${${_lib_name}}][${Brotli_INCLUDE_DIR}]"
)
endforeach()
endif() endif()

View File

@@ -1,6 +1,6 @@
#CXX = clang++ #CXX = clang++
CXXFLAGS = -std=c++14 -I.. -Wall -Wextra -pthread CXXFLAGS = -std=c++11 -I.. -Wall -Wextra -pthread
OPENSSL_DIR = /usr/local/opt/openssl OPENSSL_DIR = /usr/local/opt/openssl
OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto OPENSSL_SUPPORT = -DCPPHTTPLIB_OPENSSL_SUPPORT -I$(OPENSSL_DIR)/include -L$(OPENSSL_DIR)/lib -lssl -lcrypto

View File

@@ -23,12 +23,12 @@ int main(void) {
httplib::Client cli("localhost", 8080); httplib::Client cli("localhost", 8080);
#endif #endif
auto res = cli.Get("/hi"); if (auto res = cli.Get("/hi")) {
if (res) {
cout << res->status << endl; cout << res->status << endl;
cout << res->get_header_value("Content-Type") << endl; cout << res->get_header_value("Content-Type") << endl;
cout << res->body << endl; cout << res->body << endl;
} else { } else {
cout << "error code: " << res.error() << std::endl;
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT #ifdef CPPHTTPLIB_OPENSSL_SUPPORT
auto result = cli.get_openssl_verify_result(); auto result = cli.get_openssl_verify_result();
if (result) { if (result) {

View File

@@ -17,12 +17,12 @@ int main(void) {
auto scheme_host_port = "http://localhost:8080"; auto scheme_host_port = "http://localhost:8080";
#endif #endif
auto res = httplib::Client2(scheme_host_port).Get("/hi"); if (auto res = httplib::Client(scheme_host_port).Get("/hi")) {
if (res) {
cout << res->status << endl; cout << res->status << endl;
cout << res->get_header_value("Content-Type") << endl; cout << res->get_header_value("Content-Type") << endl;
cout << res->body << endl; cout << res->body << endl;
} else {
cout << res.error() << endl;
} }
return 0; return 0;

View File

@@ -11,7 +11,7 @@
using namespace std; using namespace std;
int main(void) { int main(void) {
httplib::Client2("http://localhost:1234") httplib::Client("http://localhost:1234")
.Get("/event1", [&](const char *data, size_t data_length) { .Get("/event1", [&](const char *data, size_t data_length) {
std::cout << string(data, data_length); std::cout << string(data, data_length);
return true; return true;

1400
httplib.h

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff