mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-10-05 23:03:42 +07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9af1a4a08f | ||
|
|
0654e5dab4 | ||
|
|
62e036f253 | ||
|
|
f0adfb2e0c | ||
|
|
139c816c16 | ||
|
|
9505a76491 | ||
|
|
29fd136afd | ||
|
|
f5598237b2 | ||
|
|
01058659ab | ||
|
|
66f698fab6 | ||
|
|
b9a9df4d73 | ||
|
|
25aa3ca982 | ||
|
|
2d67211183 | ||
|
|
f4c5d94d74 | ||
|
|
63a96aeb20 | ||
|
|
bbb83d12c1 | ||
|
|
2d4b42b70b | ||
|
|
1919d08f71 | ||
|
|
824c02fcd3 | ||
|
|
2c0613f211 | ||
|
|
be45ff1ff1 | ||
|
|
803ebe1e20 | ||
|
|
ba685dbe48 | ||
|
|
49c4c2f9c1 | ||
|
|
58909f5917 | ||
|
|
5982b5c360 | ||
|
|
eb1fe5b191 | ||
|
|
5e01587ed6 | ||
|
|
5935d9fa59 | ||
|
|
5bb4c12c6b | ||
|
|
85637844c9 | ||
|
|
d043b18097 | ||
|
|
31bb13abd2 | ||
|
|
8728db7477 | ||
|
|
1c50ac3667 | ||
|
|
cf386f97fd | ||
|
|
b2203bb05a | ||
|
|
f5b806d995 | ||
|
|
3895210f19 | ||
|
|
d45250fd88 | ||
|
|
528cacdc0d | ||
|
|
ed1b6afa10 | ||
|
|
08fc7085e5 | ||
|
|
8333340e2c | ||
|
|
98a0887571 | ||
|
|
b0a189e50e | ||
|
|
776b3ffbf9 | ||
|
|
a061b97677 | ||
|
|
d359e3a5f7 | ||
|
|
5928e0af1a | ||
|
|
a5005789ff | ||
|
|
fae30af47d | ||
|
|
2feea0c9ab | ||
|
|
a2e4af54b7 | ||
|
|
d0b123be26 | ||
|
|
df138366e4 | ||
|
|
c49441ae64 | ||
|
|
e1506fa186 | ||
|
|
ad9fd3bd93 | ||
|
|
05e0253195 | ||
|
|
da26b517a3 | ||
|
|
2b7a968468 | ||
|
|
240cc85ccb | ||
|
|
129e2f00b8 | ||
|
|
da746c6e67 | ||
|
|
3451da940d | ||
|
|
38a6b3e69f | ||
|
|
d1037ee9fd | ||
|
|
2ece5f116b | ||
|
|
c2b6e4ac04 | ||
|
|
8674555b88 | ||
|
|
85327e19ae | ||
|
|
ed8efea98b | ||
|
|
1ccddd1b0b | ||
|
|
992f3dc690 | ||
|
|
402d47e2cd | ||
|
|
171fc2e353 | ||
|
|
ced4160d05 | ||
|
|
5b51aa6851 | ||
|
|
dc13cde820 | ||
|
|
b0af78e340 | ||
|
|
914c8860e8 | ||
|
|
dc6a72a0fd | ||
|
|
685533ba50 | ||
|
|
6e46ccb37c | ||
|
|
ac18b70a0f | ||
|
|
e1acb949e7 | ||
|
|
ab96f49766 | ||
|
|
7b3cea5317 | ||
|
|
26deffe0c6 | ||
|
|
e07c5fec01 | ||
|
|
6e473a7c5c | ||
|
|
c74129a1c2 | ||
|
|
18e750b4e7 | ||
|
|
bf7700d192 | ||
|
|
3da925d6fe | ||
|
|
319417f26d | ||
|
|
4c3b119dde | ||
|
|
6de8684328 | ||
|
|
ccc9a9b3f4 | ||
|
|
f2bb9c45d6 | ||
|
|
9a663aa94e | ||
|
|
d0d744d520 | ||
|
|
fce8e6fefd | ||
|
|
180aa32ebf |
@@ -3,6 +3,7 @@ tags
|
|||||||
example/server
|
example/server
|
||||||
example/client
|
example/client
|
||||||
example/hello
|
example/hello
|
||||||
|
example/simplecli
|
||||||
example/simplesvr
|
example/simplesvr
|
||||||
example/benchmark
|
example/benchmark
|
||||||
example/redirect
|
example/redirect
|
||||||
|
|||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
# Environment
|
|
||||||
language: cpp
|
|
||||||
os:
|
|
||||||
- linux
|
|
||||||
- osx
|
|
||||||
|
|
||||||
# Compiler selection
|
|
||||||
compiler:
|
|
||||||
- clang
|
|
||||||
|
|
||||||
# Build/test steps
|
|
||||||
script:
|
|
||||||
- cd ${TRAVIS_BUILD_DIR}/test
|
|
||||||
- make all
|
|
||||||
+147
-16
@@ -1,29 +1,160 @@
|
|||||||
cmake_minimum_required(VERSION 3.7.0)
|
#[[
|
||||||
project(httplib)
|
Build options:
|
||||||
|
* HTTPLIB_USE_OPENSSL_IF_AVAILABLE (default on)
|
||||||
|
* HTTPLIB_USE_ZLIB_IF_AVAILABLE (default on)
|
||||||
|
* HTTPLIB_REQUIRE_OPENSSL (default off)
|
||||||
|
* HTTPLIB_REQUIRE_ZLIB (default off)
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 11)
|
After installation with Cmake, a find_package(httplib) is available.
|
||||||
|
This creates a httplib::httplib target (if found).
|
||||||
|
It can be linked like so:
|
||||||
|
|
||||||
# Include
|
target_link_libraries(your_exe httplib::httplib)
|
||||||
|
|
||||||
|
The following will build & install for later use.
|
||||||
|
|
||||||
|
Linux/macOS:
|
||||||
|
|
||||||
|
mkdir -p build
|
||||||
|
cd build
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||||
|
sudo cmake --build . --target install
|
||||||
|
|
||||||
|
Windows:
|
||||||
|
|
||||||
|
mkdir build
|
||||||
|
cd build
|
||||||
|
cmake ..
|
||||||
|
runas /user:Administrator "cmake --build . --config Release --target install"
|
||||||
|
|
||||||
|
These three variables are available after you run find_package(httplib)
|
||||||
|
* HTTPLIB_HEADER_PATH - this is the full path to the installed header.
|
||||||
|
* HTTPLIB_IS_USING_OPENSSL - a bool for if OpenSSL support is enabled.
|
||||||
|
* HTTPLIB_IS_USING_ZLIB - a bool for if ZLIB support is enabled.
|
||||||
|
|
||||||
|
Want to use precompiled headers (Cmake feature since v3.16)?
|
||||||
|
It's as simple as doing the following (before linking):
|
||||||
|
|
||||||
|
target_precompile_headers(httplib::httplib INTERFACE "${HTTPLIB_HEADER_PATH}")
|
||||||
|
]]
|
||||||
|
cmake_minimum_required(VERSION 3.7.0 FATAL_ERROR)
|
||||||
|
project(httplib LANGUAGES CXX)
|
||||||
|
|
||||||
|
# Change as needed to set an OpenSSL minimum version.
|
||||||
|
# This is used in the installed Cmake config file.
|
||||||
|
set(_HTTPLIB_OPENSSL_MIN_VER "1.1.1")
|
||||||
|
|
||||||
|
# Allow for a build to require OpenSSL to pass, instead of just being optional
|
||||||
|
option(HTTPLIB_REQUIRE_OPENSSL "Requires OpenSSL to be found & linked, or fails build." OFF)
|
||||||
|
option(HTTPLIB_REQUIRE_ZLIB "Requires ZLIB to be found & linked, or fails build." OFF)
|
||||||
|
# Allow for a build to casually enable OpenSSL/ZLIB support, but silenty continue if not found.
|
||||||
|
# Make these options so their automatic use can be specifically disabled (as needed)
|
||||||
|
option(HTTPLIB_USE_OPENSSL_IF_AVAILABLE "Uses OpenSSL (if available) to enable HTTPS support." ON)
|
||||||
|
option(HTTPLIB_USE_ZLIB_IF_AVAILABLE "Uses ZLIB (if available) to enable compression support." ON)
|
||||||
|
|
||||||
|
# TODO: implement the option of option to correctly split, building, and export with the split.py script.
|
||||||
|
# option(HTTPLIB_SPLIT "Uses a Python script to split the header into a header & source file." OFF)
|
||||||
|
|
||||||
|
# Threads needed for <thread> on some systems, and for <pthread.h> on Linux
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
if(HTTPLIB_REQUIRE_OPENSSL)
|
||||||
|
find_package(OpenSSL ${_HTTPLIB_OPENSSL_MIN_VER} REQUIRED)
|
||||||
|
elseif(HTTPLIB_USE_OPENSSL_IF_AVAILABLE)
|
||||||
|
# Look quietly since it's optional are optional
|
||||||
|
find_package(OpenSSL ${_HTTPLIB_OPENSSL_MIN_VER} QUIET)
|
||||||
|
endif()
|
||||||
|
if(HTTPLIB_REQUIRE_ZLIB)
|
||||||
|
find_package(ZLIB REQUIRED)
|
||||||
|
elseif(HTTPLIB_USE_ZLIB_IF_AVAILABLE)
|
||||||
|
find_package(ZLIB QUIET)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Used for default, common dirs that the end-user can change (if needed)
|
||||||
|
# like CMAKE_INSTALL_INCLUDEDIR or CMAKE_INSTALL_DATADIR
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
include(ExternalProject)
|
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} INTERFACE)
|
add_library(${PROJECT_NAME} INTERFACE)
|
||||||
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)
|
# Lets you address the target with httplib::httplib
|
||||||
|
# Only useful if building in-tree, versus using it from an installation.
|
||||||
|
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
|
||||||
|
|
||||||
|
# Might be missing some, but this list is somewhat comprehensive
|
||||||
|
target_compile_features(${PROJECT_NAME} INTERFACE
|
||||||
|
cxx_std_11
|
||||||
|
cxx_nullptr
|
||||||
|
cxx_noexcept
|
||||||
|
cxx_lambdas
|
||||||
|
cxx_override
|
||||||
|
cxx_defaulted_functions
|
||||||
|
cxx_attribute_deprecated
|
||||||
|
cxx_auto_type
|
||||||
|
cxx_decltype
|
||||||
|
cxx_deleted_functions
|
||||||
|
cxx_range_for
|
||||||
|
cxx_sizeof_member
|
||||||
|
)
|
||||||
|
|
||||||
target_include_directories(${PROJECT_NAME} INTERFACE
|
target_include_directories(${PROJECT_NAME} INTERFACE
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||||
$<INSTALL_INTERFACE:include>)
|
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||||
|
|
||||||
install(TARGETS ${PROJECT_NAME} EXPORT httplibConfig
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
||||||
|
|
||||||
install(FILES httplib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
|
target_link_libraries(${PROJECT_NAME} INTERFACE
|
||||||
|
# Always require threads
|
||||||
|
Threads::Threads
|
||||||
|
# Only link zlib & openssl if they're found
|
||||||
|
$<$<BOOL:${ZLIB_FOUND}>:ZLIB::ZLIB>
|
||||||
|
$<$<BOOL:${OPENSSL_FOUND}>:OpenSSL::SSL OpenSSL::Crypto>
|
||||||
|
)
|
||||||
|
|
||||||
install(EXPORT httplibConfig DESTINATION share/httplib/cmake)
|
# Auto-define the optional support if those packages were found
|
||||||
|
target_compile_definitions(${PROJECT_NAME} INTERFACE
|
||||||
|
$<$<BOOL:${ZLIB_FOUND}>:CPPHTTPLIB_ZLIB_SUPPORT>
|
||||||
|
$<$<BOOL:${OPENSSL_FOUND}>:CPPHTTPLIB_OPENSSL_SUPPORT>
|
||||||
|
)
|
||||||
|
|
||||||
export(TARGETS ${PROJECT_NAME} FILE httplibConfig.cmake)
|
# Cmake's find_package search path is different based on the system
|
||||||
|
# See https://cmake.org/cmake/help/latest/command/find_package.html for the list
|
||||||
|
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||||
|
set(_TARGET_INSTALL_CMAKEDIR "${CMAKE_INSTALL_PREFIX}/cmake/${PROJECT_NAME}")
|
||||||
|
else()
|
||||||
|
# On Non-Windows, it should be /usr/lib/cmake/<name>/<name>Config.cmake
|
||||||
|
# NOTE: This may or may not work for macOS...
|
||||||
|
set(_TARGET_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
|
||||||
|
endif()
|
||||||
|
|
||||||
#add_subdirectory(example)
|
include(CMakePackageConfigHelpers)
|
||||||
#add_subdirectory(test)
|
|
||||||
|
# Configures the meta-file httplibConfig.cmake.in to replace variables with paths/values/etc.
|
||||||
|
configure_package_config_file("${PROJECT_NAME}Config.cmake.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
INSTALL_DESTINATION "${_TARGET_INSTALL_CMAKEDIR}"
|
||||||
|
# Passes the includedir install path
|
||||||
|
PATH_VARS CMAKE_INSTALL_FULL_INCLUDEDIR
|
||||||
|
# There aren't any components, so don't use the macro
|
||||||
|
NO_CHECK_REQUIRED_COMPONENTS_MACRO
|
||||||
|
)
|
||||||
|
|
||||||
|
# Creates the export httplibTargets.cmake
|
||||||
|
# This is strictly what holds compilation requirements
|
||||||
|
# and linkage information (doesn't find deps though).
|
||||||
|
install(TARGETS ${PROJECT_NAME}
|
||||||
|
EXPORT httplibTargets
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(FILES httplib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
|
|
||||||
|
install(FILES
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||||
|
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
# NOTE: This path changes depending on if it's on Windows or Linux
|
||||||
|
install(EXPORT httplibTargets
|
||||||
|
# Puts the targets into the httplib namespace
|
||||||
|
# So this makes httplib::httplib linkable after doing find_package(httplib)
|
||||||
|
NAMESPACE ${PROJECT_NAME}::
|
||||||
|
DESTINATION ${_TARGET_INSTALL_CMAKEDIR}
|
||||||
|
)
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ cpp-httplib
|
|||||||
===========
|
===========
|
||||||
|
|
||||||
[](https://github.com/yhirose/cpp-httplib/actions)
|
[](https://github.com/yhirose/cpp-httplib/actions)
|
||||||
[](https://travis-ci.org/yhirose/cpp-httplib)
|
|
||||||
[](https://ci.appveyor.com/project/yhirose/cpp-httplib)
|
[](https://ci.appveyor.com/project/yhirose/cpp-httplib)
|
||||||
|
|
||||||
A C++11 single-file header-only cross platform HTTP/HTTPS library.
|
A C++11 single-file header-only cross platform HTTP/HTTPS library.
|
||||||
|
|
||||||
It's extremely easy to setup. Just include **httplib.h** file in your code!
|
It's extremely easy to setup. Just include **httplib.h** file in your code!
|
||||||
|
|
||||||
|
For Windows users: Please read [this note](https://github.com/yhirose/cpp-httplib#windows).
|
||||||
|
|
||||||
Server Example
|
Server Example
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
@@ -30,6 +31,16 @@ int main(void)
|
|||||||
res.set_content(numbers, "text/plain");
|
res.set_content(numbers, "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
svr.Get("/body-header-param", [](const Request& req, Response& res) {
|
||||||
|
if (req.has_header("Content-Length")) {
|
||||||
|
auto val = req.get_header_value("Content-Length");
|
||||||
|
}
|
||||||
|
if (req.has_param("key")) {
|
||||||
|
auto val = req.get_param_value("key");
|
||||||
|
}
|
||||||
|
res.set_content(req.body, "text/plain");
|
||||||
|
});
|
||||||
|
|
||||||
svr.Get("/stop", [&](const Request& req, Response& res) {
|
svr.Get("/stop", [&](const Request& req, Response& res) {
|
||||||
svr.stop();
|
svr.stop();
|
||||||
});
|
});
|
||||||
@@ -160,16 +171,17 @@ svr.Post("/content_receiver",
|
|||||||
### Send content with Content provider
|
### Send content with Content provider
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
const uint64_t DATA_CHUNK_SIZE = 4;
|
const size_t DATA_CHUNK_SIZE = 4;
|
||||||
|
|
||||||
svr.Get("/stream", [&](const Request &req, Response &res) {
|
svr.Get("/stream", [&](const Request &req, Response &res) {
|
||||||
auto data = new std::string("abcdefg");
|
auto data = new std::string("abcdefg");
|
||||||
|
|
||||||
res.set_content_provider(
|
res.set_content_provider(
|
||||||
data->size(), // Content length
|
data->size(), // Content length
|
||||||
[data](uint64_t offset, uint64_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));
|
||||||
|
return true; // return 'false' if you want to cancel the process.
|
||||||
},
|
},
|
||||||
[data] { delete data; });
|
[data] { delete data; });
|
||||||
});
|
});
|
||||||
@@ -180,11 +192,12 @@ svr.Get("/stream", [&](const Request &req, Response &res) {
|
|||||||
```cpp
|
```cpp
|
||||||
svr.Get("/chunked", [&](const Request& req, Response& res) {
|
svr.Get("/chunked", [&](const Request& req, Response& res) {
|
||||||
res.set_chunked_content_provider(
|
res.set_chunked_content_provider(
|
||||||
[](uint64_t offset, DataSink &sink) {
|
[](size_t offset, DataSink &sink) {
|
||||||
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();
|
||||||
|
return true; // return 'false' if you want to cancel the process.
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -248,14 +261,13 @@ svr.set_expect_100_continue_handler([](const Request &req, Response &res) {
|
|||||||
Client Example
|
Client Example
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
### GET
|
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
#include <httplib.h>
|
#include <httplib.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
|
// IMPORTANT: 1st parameter must be a hostname or an IP adress string.
|
||||||
httplib::Client cli("localhost", 1234);
|
httplib::Client cli("localhost", 1234);
|
||||||
|
|
||||||
auto res = cli.Get("/hi");
|
auto res = cli.Get("/hi");
|
||||||
@@ -280,7 +292,7 @@ auto res = cli.Get("/hi", headers);
|
|||||||
std::string body;
|
std::string body;
|
||||||
|
|
||||||
auto res = cli.Get("/large-data",
|
auto res = cli.Get("/large-data",
|
||||||
[&](const char *data, uint64_t data_length) {
|
[&](const char *data, size_t data_length) {
|
||||||
body.append(data, data_length);
|
body.append(data, data_length);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
@@ -353,6 +365,35 @@ res = cli.Options("/resource/foo");
|
|||||||
```c++
|
```c++
|
||||||
cli.set_timeout_sec(5); // timeouts in 5 seconds
|
cli.set_timeout_sec(5); // timeouts in 5 seconds
|
||||||
```
|
```
|
||||||
|
### Receive content with Content receiver
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::string body;
|
||||||
|
auto res = cli.Get(
|
||||||
|
"/stream", Headers(),
|
||||||
|
[&](const Response &response) {
|
||||||
|
EXPECT_EQ(200, response.status);
|
||||||
|
return true; // return 'false' if you want to cancel the request.
|
||||||
|
},
|
||||||
|
[&](const char *data, size_t data_length) {
|
||||||
|
body.append(data, data_length);
|
||||||
|
return true; // return 'false' if you want to cancel the request.
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
### Send content with Content provider
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
std::string body = ...;
|
||||||
|
auto res = cli_.Post(
|
||||||
|
"/stream", body.size(),
|
||||||
|
[](size_t offset, size_t length, DataSink &sink) {
|
||||||
|
sink.write(body.data() + offset, length);
|
||||||
|
return true; // return 'false' if you want to cancel the request.
|
||||||
|
},
|
||||||
|
"text/plain");
|
||||||
|
```
|
||||||
|
|
||||||
### With Progress Callback
|
### With Progress Callback
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
@@ -363,7 +404,7 @@ std::shared_ptr<httplib::Response> 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/total)*100));
|
(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.
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -426,6 +467,15 @@ Get(requests, "/get-request2");
|
|||||||
Post(requests, "/post-request1", "text", "text/plain");
|
Post(requests, "/post-request1", "text", "text/plain");
|
||||||
Post(requests, "/post-request2", "text", "text/plain");
|
Post(requests, "/post-request2", "text", "text/plain");
|
||||||
|
|
||||||
|
const size_t DATA_CHUNK_SIZE = 4;
|
||||||
|
std::string data("abcdefg");
|
||||||
|
Post(requests, "/post-request-with-content-provider",
|
||||||
|
data.size(),
|
||||||
|
[&](size_t offset, size_t length, DataSink &sink){
|
||||||
|
sink.write(&data[offset], std::min(length, DATA_CHUNK_SIZE));
|
||||||
|
},
|
||||||
|
"text/plain");
|
||||||
|
|
||||||
std::vector<Response> responses;
|
std::vector<Response> responses;
|
||||||
if (cli.send(requests, responses)) {
|
if (cli.send(requests, responses)) {
|
||||||
for (const auto& res: responses) {
|
for (const auto& res: responses) {
|
||||||
@@ -475,7 +525,7 @@ cli.enable_server_certificate_verification(true);
|
|||||||
Zlib Support
|
Zlib Support
|
||||||
------------
|
------------
|
||||||
|
|
||||||
'gzip' compression is available with `CPPHTTPLIB_ZLIB_SUPPORT`.
|
'gzip' compression is available with `CPPHTTPLIB_ZLIB_SUPPORT`. `libz` should be linked.
|
||||||
|
|
||||||
The server applies gzip compression to the following MIME type contents:
|
The server applies gzip compression to the following MIME type contents:
|
||||||
|
|
||||||
@@ -505,8 +555,27 @@ httplib.h httplib.cc
|
|||||||
NOTE
|
NOTE
|
||||||
----
|
----
|
||||||
|
|
||||||
|
### g++
|
||||||
|
|
||||||
g++ 4.8 and below cannot build this library since `<regex>` in the versions are [broken](https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions).
|
g++ 4.8 and below cannot build this library since `<regex>` in the versions are [broken](https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions).
|
||||||
|
|
||||||
|
### Windows
|
||||||
|
|
||||||
|
Include `httplib.h` before `Windows.h` or include `Windows.h` by defining `WIN32_LEAN_AND_MEAN` beforehand.
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#include <httplib.h>
|
||||||
|
#include <Windows.h>
|
||||||
|
```
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <httplib.h>
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: Cygwin on Windows is not supported.
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|
||||||
@@ -515,43 +584,4 @@ MIT license (© 2020 Yuji Hirose)
|
|||||||
Special Thanks To
|
Special Thanks To
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
The following folks made great contributions to polish this library to totally another level from a simple toy!
|
[These folks](https://github.com/yhirose/cpp-httplib/graphs/contributors) made great contributions to polish this library to totally another level from a simple toy!
|
||||||
|
|
||||||
* [Zefz](https://github.com/Zefz)
|
|
||||||
* [PixlRainbow](https://github.com/PixlRainbow)
|
|
||||||
* [sgraham](https://github.com/sgraham)
|
|
||||||
* [mrexodia](https://github.com/mrexodia)
|
|
||||||
* [hyperxor](https://github.com/hyperxor)
|
|
||||||
* [omaralvarez](https://github.com/omaralvarez)
|
|
||||||
* [vvanelslande](https://github.com/vvanelslande)
|
|
||||||
* [underscorediscovery](https://github.com/underscorediscovery)
|
|
||||||
* [sux2mfgj](https://github.com/sux2mfgj)
|
|
||||||
* [matvore](https://github.com/matvore)
|
|
||||||
* [intmain-io](https://github.com/intmain)
|
|
||||||
* [davidgfnet](https://github.com/davidgfnet)
|
|
||||||
* [crtxcr](https://github.com/crtxcr)
|
|
||||||
* [const-volatile](https://github.com/const)
|
|
||||||
* [aguadoenzo](https://github.com/aguadoenzo)
|
|
||||||
* [TheMaverickProgrammer](https://github.com/TheMaverickProgrammer)
|
|
||||||
* [vdudouyt](https://github.com/vdudouyt)
|
|
||||||
* [stupedama](https://github.com/stupedama)
|
|
||||||
* [rockwotj](https://github.com/rockwotj)
|
|
||||||
* [marknelson](https://github.com/marknelson)
|
|
||||||
* [jaspervandeven](https://github.com/jaspervandeven)
|
|
||||||
* [hans-erickson](https://github.com/hans)
|
|
||||||
* [ha11owed](https://github.com/ha11owed)
|
|
||||||
* [gulrak](https://github.com/gulrak)
|
|
||||||
* [dolphineye](https://github.com/dolphineye)
|
|
||||||
* [danielzehe](https://github.com/danielzehe)
|
|
||||||
* [batist73](https://github.com/batist73)
|
|
||||||
* [barryam3](https://github.com/barryam3)
|
|
||||||
* [adikabintang](https://github.com/adikabintang)
|
|
||||||
* [aaronalbers](https://github.com/aaronalbers)
|
|
||||||
* [Whitetigerswt](https://github.com/Whitetigerswt)
|
|
||||||
* [TangHuaiZhe](https://github.com/TangHuaiZhe)
|
|
||||||
* [Sil3ntStorm](https://github.com/Sil3ntStorm)
|
|
||||||
* [MannyClicks](https://github.com/MannyClicks)
|
|
||||||
* [DraTeots](https://github.com/DraTeots)
|
|
||||||
* [BastienDurel](https://github.com/BastienDurel)
|
|
||||||
* [vitalyster](https://github.com/vitalyster)
|
|
||||||
* [trollixx](https://github.com/trollixx)
|
|
||||||
|
|||||||
+11
-6
@@ -1,9 +1,14 @@
|
|||||||
version: 1.0.{build}
|
image:
|
||||||
image: Visual Studio 2017
|
- Visual Studio 2019
|
||||||
|
|
||||||
|
platform:
|
||||||
|
- x64
|
||||||
|
|
||||||
build_script:
|
build_script:
|
||||||
- cmd: >-
|
- cmd: >-
|
||||||
cd test
|
cd test
|
||||||
|
|
||||||
|
msbuild.exe test.sln /verbosity:minimal /t:Build /p:Configuration=Release;Platform=%PLATFORM%
|
||||||
|
|
||||||
msbuild.exe test.sln /verbosity:minimal /t:Build /p:Configuration=Debug;Platform=Win32
|
|
||||||
test_script:
|
test_script:
|
||||||
- cmd: Debug\test.exe
|
- cmd: x64\Release\test.exe
|
||||||
|
|||||||
+5
-2
@@ -5,7 +5,7 @@ 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
|
||||||
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
||||||
|
|
||||||
all: server client hello simplesvr upload redirect sse benchmark
|
all: server client hello simplecli simplesvr upload redirect sse benchmark
|
||||||
|
|
||||||
server : server.cc ../httplib.h Makefile
|
server : server.cc ../httplib.h Makefile
|
||||||
$(CXX) -o server $(CXXFLAGS) server.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT)
|
$(CXX) -o server $(CXXFLAGS) server.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT)
|
||||||
@@ -16,6 +16,9 @@ client : client.cc ../httplib.h Makefile
|
|||||||
hello : hello.cc ../httplib.h Makefile
|
hello : hello.cc ../httplib.h Makefile
|
||||||
$(CXX) -o hello $(CXXFLAGS) hello.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT)
|
$(CXX) -o hello $(CXXFLAGS) hello.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT)
|
||||||
|
|
||||||
|
simplecli : simplecli.cc ../httplib.h Makefile
|
||||||
|
$(CXX) -o simplecli $(CXXFLAGS) simplecli.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT)
|
||||||
|
|
||||||
simplesvr : simplesvr.cc ../httplib.h Makefile
|
simplesvr : simplesvr.cc ../httplib.h Makefile
|
||||||
$(CXX) -o simplesvr $(CXXFLAGS) simplesvr.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT)
|
$(CXX) -o simplesvr $(CXXFLAGS) simplesvr.cc $(OPENSSL_SUPPORT) $(ZLIB_SUPPORT)
|
||||||
|
|
||||||
@@ -36,4 +39,4 @@ pem:
|
|||||||
openssl req -new -key key.pem | openssl x509 -days 3650 -req -signkey key.pem > cert.pem
|
openssl req -new -key key.pem | openssl x509 -days 3650 -req -signkey key.pem > cert.pem
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm server client hello simplesvr upload redirect sse benchmark *.pem
|
rm server client hello simplecli simplesvr upload redirect sse benchmark *.pem
|
||||||
|
|||||||
+1
-1
@@ -15,5 +15,5 @@ int main(void) {
|
|||||||
res.set_content("Hello World!", "text/plain");
|
res.set_content("Hello World!", "text/plain");
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.listen("localhost", 1234);
|
svr.listen("localhost", 8080);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
//
|
||||||
|
// simplecli.cc
|
||||||
|
//
|
||||||
|
// Copyright (c) 2019 Yuji Hirose. All rights reserved.
|
||||||
|
// MIT License
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <httplib.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define CA_CERT_FILE "./ca-bundle.crt"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
||||||
|
auto res = httplib::Client2("https://localhost:8080")
|
||||||
|
.set_ca_cert_path(CA_CERT_FILE)
|
||||||
|
// .enable_server_certificate_verification(true)
|
||||||
|
.Get("/hi");
|
||||||
|
#else
|
||||||
|
auto res = httplib::Client2("http://localhost:8080").Get("/hi");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
cout << res->status << endl;
|
||||||
|
cout << res->get_header_value("Content-Type") << endl;
|
||||||
|
cout << res->body << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -127,7 +127,7 @@ int main(int argc, const char **argv) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << "The server started at port " << port << "...";
|
cout << "The server started at port " << port << "..." << endl;
|
||||||
|
|
||||||
svr.listen("localhost", port);
|
svr.listen("localhost", port);
|
||||||
|
|
||||||
|
|||||||
+8
-4
@@ -80,15 +80,19 @@ int main(void) {
|
|||||||
svr.Get("/event1", [&](const Request & /*req*/, Response &res) {
|
svr.Get("/event1", [&](const Request & /*req*/, Response &res) {
|
||||||
cout << "connected to event1..." << endl;
|
cout << "connected to event1..." << endl;
|
||||||
res.set_header("Content-Type", "text/event-stream");
|
res.set_header("Content-Type", "text/event-stream");
|
||||||
res.set_chunked_content_provider(
|
res.set_chunked_content_provider([&](size_t /*offset*/, DataSink &sink) {
|
||||||
[&](uint64_t /*offset*/, DataSink &sink) { ed.wait_event(&sink); });
|
ed.wait_event(&sink);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
svr.Get("/event2", [&](const Request & /*req*/, Response &res) {
|
svr.Get("/event2", [&](const Request & /*req*/, Response &res) {
|
||||||
cout << "connected to event2..." << endl;
|
cout << "connected to event2..." << endl;
|
||||||
res.set_header("Content-Type", "text/event-stream");
|
res.set_header("Content-Type", "text/event-stream");
|
||||||
res.set_chunked_content_provider(
|
res.set_chunked_content_provider([&](size_t /*offset*/, DataSink &sink) {
|
||||||
[&](uint64_t /*offset*/, DataSink &sink) { ed.wait_event(&sink); });
|
ed.wait_event(&sink);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
thread t([&] {
|
thread t([&] {
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
# Generates a macro to auto-configure everything
|
||||||
|
@PACKAGE_INIT@
|
||||||
|
|
||||||
|
include(CMakeFindDependencyMacro)
|
||||||
|
|
||||||
|
# We add find_dependency calls here to not make the end-user have to call them.
|
||||||
|
find_dependency(Threads REQUIRED)
|
||||||
|
if(@HTTPLIB_REQUIRE_OPENSSL@)
|
||||||
|
find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@ REQUIRED)
|
||||||
|
# Lets you check if these options were correctly enabled for your install
|
||||||
|
set(HTTPLIB_IS_USING_OPENSSL TRUE)
|
||||||
|
elseif(@HTTPLIB_USE_OPENSSL_IF_AVAILABLE@)
|
||||||
|
# Look quietly since it's optional
|
||||||
|
find_dependency(OpenSSL @_HTTPLIB_OPENSSL_MIN_VER@ QUIET)
|
||||||
|
# Lets you check if these options were correctly enabled for your install
|
||||||
|
set(HTTPLIB_IS_USING_OPENSSL @OPENSSL_FOUND@)
|
||||||
|
else()
|
||||||
|
set(HTTPLIB_IS_USING_OPENSSL FALSE)
|
||||||
|
endif()
|
||||||
|
if(@HTTPLIB_REQUIRE_ZLIB@)
|
||||||
|
find_dependency(ZLIB REQUIRED)
|
||||||
|
# Lets you check if these options were correctly enabled for your install
|
||||||
|
set(HTTPLIB_IS_USING_ZLIB TRUE)
|
||||||
|
elseif(@HTTPLIB_USE_ZLIB_IF_AVAILABLE@)
|
||||||
|
# Look quietly since it's optional
|
||||||
|
find_dependency(ZLIB QUIET)
|
||||||
|
# Lets you check if these options were correctly enabled for your install
|
||||||
|
set(HTTPLIB_IS_USING_ZLIB @ZLIB_FOUND@)
|
||||||
|
else()
|
||||||
|
set(HTTPLIB_IS_USING_ZLIB FALSE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Lets the end-user find the header path if needed
|
||||||
|
# This is helpful if you're using Cmake's pre-compiled header feature
|
||||||
|
set_and_check(HTTPLIB_HEADER_PATH "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/httplib.h")
|
||||||
|
|
||||||
|
# Brings in the target library
|
||||||
|
include("${CMAKE_CURRENT_LIST_DIR}/httplibTargets.cmake")
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#CXX = clang++
|
#CXX = clang++
|
||||||
CXXFLAGS = -ggdb -O0 -std=c++11 -DGTEST_USE_OWN_TR1_TUPLE -I.. -I. -Wall -Wextra -Wtype-limits
|
CXXFLAGS = -ggdb -O0 -std=c++11 -DGTEST_USE_OWN_TR1_TUPLE -I.. -I. -Wall -Wextra -Wtype-limits -Wconversion
|
||||||
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
|
||||||
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
ZLIB_SUPPORT = -DCPPHTTPLIB_ZLIB_SUPPORT -lz
|
||||||
|
|||||||
+14
-1
@@ -38,6 +38,14 @@
|
|||||||
// when it's fused.
|
// when it's fused.
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
#if __clang__
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wsign-conversion"
|
||||||
|
#elif __GNUC__
|
||||||
|
#pragma gcc diagnostic push
|
||||||
|
#pragma gcc diagnostic ignored "-Wsign-conversion"
|
||||||
|
#endif
|
||||||
|
|
||||||
// The following lines pull in the real gtest *.cc files.
|
// The following lines pull in the real gtest *.cc files.
|
||||||
// Copyright 2005, Google Inc.
|
// Copyright 2005, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
@@ -9039,7 +9047,6 @@ void HasNewFatalFailureHelper::ReportTestPartResult(
|
|||||||
//
|
//
|
||||||
// Author: wan@google.com (Zhanyong Wan)
|
// Author: wan@google.com (Zhanyong Wan)
|
||||||
|
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
@@ -9116,3 +9123,9 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
|
|||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace testing
|
} // namespace testing
|
||||||
|
|
||||||
|
#if __clang__
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#elif __GNUC__
|
||||||
|
#pragma gcc diagnostic pop
|
||||||
|
#endif
|
||||||
|
|||||||
+15
-1
@@ -59,6 +59,14 @@
|
|||||||
#pragma warning(disable : 4996)
|
#pragma warning(disable : 4996)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __clang__
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wsign-compare"
|
||||||
|
#elif __GNUC__
|
||||||
|
#pragma gcc diagnostic push
|
||||||
|
#pragma gcc diagnostic ignored "-Wsign-compare"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Copyright 2005, Google Inc.
|
// Copyright 2005, Google Inc.
|
||||||
// All rights reserved.
|
// All rights reserved.
|
||||||
//
|
//
|
||||||
@@ -7311,7 +7319,7 @@ inline const char* SkipComma(const char* str) {
|
|||||||
// the entire string if it contains no comma.
|
// the entire string if it contains no comma.
|
||||||
inline String GetPrefixUntilComma(const char* str) {
|
inline String GetPrefixUntilComma(const char* str) {
|
||||||
const char* comma = strchr(str, ',');
|
const char* comma = strchr(str, ',');
|
||||||
return comma == NULL ? String(str) : String(str, comma - str);
|
return comma == NULL ? String(str) : String(str, static_cast<size_t>(comma - str));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TypeParameterizedTest<Fixture, TestSel, Types>::Register()
|
// TypeParameterizedTest<Fixture, TestSel, Types>::Register()
|
||||||
@@ -19553,4 +19561,10 @@ bool StaticAssertTypeEq() {
|
|||||||
#pragma warning( pop )
|
#pragma warning( pop )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if __clang__
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#elif __GNUC__
|
||||||
|
#pragma gcc diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // GTEST_INCLUDE_GTEST_GTEST_H_
|
#endif // GTEST_INCLUDE_GTEST_GTEST_H_
|
||||||
|
|||||||
+651
-83
File diff suppressed because it is too large
Load Diff
+13
-13
@@ -28,7 +28,7 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>true</UseDebugLibraries>
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
@@ -40,7 +40,7 @@
|
|||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
<ConfigurationType>Application</ConfigurationType>
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
<UseDebugLibraries>false</UseDebugLibraries>
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
<PlatformToolset>v141</PlatformToolset>
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>Unicode</CharacterSet>
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -69,13 +69,13 @@
|
|||||||
<PropertyGroup Label="UserMacros" />
|
<PropertyGroup Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<LinkIncremental>true</LinkIncremental>
|
<LinkIncremental>true</LinkIncremental>
|
||||||
<IncludePath>C:\Program Files\OpenSSL-Win64\lib\VC;C:\Program Files\OpenSSL-Win64\include;$(IncludePath)</IncludePath>
|
<IncludePath>$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
<LinkIncremental>true</LinkIncremental>
|
<LinkIncremental>true</LinkIncremental>
|
||||||
<IncludePath>C:\Program Files\OpenSSL-Win64\include;$(IncludePath)</IncludePath>
|
<IncludePath>$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>C:\Program Files\OpenSSL-Win64\lib;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<LinkIncremental>false</LinkIncremental>
|
<LinkIncremental>false</LinkIncremental>
|
||||||
@@ -84,14 +84,14 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<LinkIncremental>false</LinkIncremental>
|
<LinkIncremental>false</LinkIncremental>
|
||||||
<IncludePath>C:\Program Files\OpenSSL-Win64\include;$(IncludePath)</IncludePath>
|
<IncludePath>$(IncludePath)</IncludePath>
|
||||||
<LibraryPath>C:\Program Files\OpenSSL-Win64\lib;$(LibraryPath)</LibraryPath>
|
<LibraryPath>$(LibraryPath)</LibraryPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
|
||||||
@@ -108,7 +108,7 @@
|
|||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<Optimization>Disabled</Optimization>
|
<Optimization>Disabled</Optimization>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>./;../</AdditionalIncludeDirectories>
|
||||||
@@ -118,12 +118,12 @@
|
|||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalDependencies>Ws2_32.lib;libssl.lib;libcrypto.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
@@ -144,7 +144,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<WarningLevel>Level3</WarningLevel>
|
<WarningLevel>Level4</WarningLevel>
|
||||||
<PrecompiledHeader>
|
<PrecompiledHeader>
|
||||||
</PrecompiledHeader>
|
</PrecompiledHeader>
|
||||||
<Optimization>MaxSpeed</Optimization>
|
<Optimization>MaxSpeed</Optimization>
|
||||||
@@ -160,7 +160,7 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<AdditionalDependencies>Ws2_32.lib;libssl.lib;libcrypto.lib;libssl.lib;libcrypto.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>Ws2_32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
+10
-8
@@ -185,15 +185,17 @@ void DigestAuthTestFromHTTPWatch(Client& cli) {
|
|||||||
for (auto path : paths) {
|
for (auto path : paths) {
|
||||||
auto res = cli.Get(path.c_str());
|
auto res = cli.Get(path.c_str());
|
||||||
ASSERT_TRUE(res != nullptr);
|
ASSERT_TRUE(res != nullptr);
|
||||||
EXPECT_EQ(400, res->status);
|
EXPECT_EQ(401, res->status);
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.set_digest_auth("bad", "world");
|
// NOTE: Until httpbin.org fixes issue #46, the following test is commented
|
||||||
for (auto path : paths) {
|
// out. Plese see https://httpbin.org/digest-auth/auth/hello/world
|
||||||
auto res = cli.Get(path.c_str());
|
// cli.set_digest_auth("bad", "world");
|
||||||
ASSERT_TRUE(res != nullptr);
|
// for (auto path : paths) {
|
||||||
EXPECT_EQ(400, res->status);
|
// auto res = cli.Get(path.c_str());
|
||||||
}
|
// ASSERT_TRUE(res != nullptr);
|
||||||
|
// EXPECT_EQ(401, res->status);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +268,7 @@ void KeepAliveTest(Client& cli, bool basic) {
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
int count = paths.size();
|
int count = static_cast<int>(paths.size());
|
||||||
while (count--) {
|
while (count--) {
|
||||||
auto &res = responses[i++];
|
auto &res = responses[i++];
|
||||||
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res.body);
|
EXPECT_EQ("{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n", res.body);
|
||||||
|
|||||||
Reference in New Issue
Block a user