From 9afe7507c740c94349af3db681d3681305444df4 Mon Sep 17 00:00:00 2001 From: yhirose Date: Fri, 15 Nov 2024 23:59:01 -0500 Subject: [PATCH 01/11] Update test.yaml Support CMake build on Windows --- .github/workflows/test.yaml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index cf2104feee..5a84b28496 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -35,9 +35,18 @@ jobs: uses: actions/checkout@v4 - name: setup msbuild on windows uses: microsoft/setup-msbuild@v2 - - name: make-windows + - name: build and run tests run: | cd test msbuild.exe test.sln /verbosity:minimal /t:Build "/p:Configuration=Release;Platform=x64" - x64\Release\test.exe - + x64\Release\test.exe + - name: Install libraries + run: | + vcpkg install gtest curl zlib brotli + choco openssl + - name: Configure CMake for Release + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + - name: Build with CMake + run: cmake --build build --config Release + - name: Run tests with CTest + run: ctest --output-on-failure --test-dir build -C Release From 7059ab855a05b0c705196f7e46f9867f805ac129 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 00:12:10 -0500 Subject: [PATCH 02/11] Update test.yaml --- .github/workflows/test.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 5a84b28496..656352bea3 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -27,26 +27,29 @@ jobs: windows: runs-on: windows-latest steps: - - name: prepare git for checkout on windows + - name: Prepare Git for Checkout on Windows run: | git config --global core.autocrlf false git config --global core.eol lf - - name: checkout + - name: Checkout uses: actions/checkout@v4 + - name: Export GitHub Actions cache environment variables + uses: actions/github-script@v7 + with: + script: | + core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); + core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - name: setup msbuild on windows uses: microsoft/setup-msbuild@v2 - - name: build and run tests - run: | - cd test - msbuild.exe test.sln /verbosity:minimal /t:Build "/p:Configuration=Release;Platform=x64" - x64\Release\test.exe - name: Install libraries run: | vcpkg install gtest curl zlib brotli - choco openssl + choco install openssl - name: Configure CMake for Release run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - name: Build with CMake run: cmake --build build --config Release - name: Run tests with CTest run: ctest --output-on-failure --test-dir build -C Release + env: + VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" From 0297fbef00a2a36a444ac81bee2d908a2e89be03 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 00:19:04 -0500 Subject: [PATCH 03/11] Update test.yaml --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 656352bea3..1fbe145d5f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -46,7 +46,7 @@ jobs: vcpkg install gtest curl zlib brotli choco install openssl - name: Configure CMake for Release - run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - name: Build with CMake run: cmake --build build --config Release - name: Run tests with CTest From a34e780dcef89fc363d5f737df20611164a115ff Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 00:32:43 -0500 Subject: [PATCH 04/11] Update test.yaml --- .github/workflows/test.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1fbe145d5f..b51160cad9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -46,10 +46,11 @@ jobs: vcpkg install gtest curl zlib brotli choco install openssl - name: Configure CMake for Release - run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - name: Build with CMake run: cmake --build build --config Release - name: Run tests with CTest run: ctest --output-on-failure --test-dir build -C Release - env: + env: + VCPKG_ROOT: ${{ VCPKG_INSTALLATION_ROOT }} VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" From b60d25dd14867b2ff44746c06295cafc06619d6a Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 00:39:51 -0500 Subject: [PATCH 05/11] Update test.yaml --- .github/workflows/test.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b51160cad9..888c7c37ae 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -46,11 +46,10 @@ jobs: vcpkg install gtest curl zlib brotli choco install openssl - name: Configure CMake for Release - run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_INSTALLATION_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - name: Build with CMake run: cmake --build build --config Release - name: Run tests with CTest run: ctest --output-on-failure --test-dir build -C Release env: - VCPKG_ROOT: ${{ VCPKG_INSTALLATION_ROOT }} VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" From eb45b17389c491f10cb7e130783e40265465e9b4 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 00:49:09 -0500 Subject: [PATCH 06/11] Update test.yaml --- .github/workflows/test.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 888c7c37ae..9f8c1bb9c4 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -43,10 +43,11 @@ jobs: uses: microsoft/setup-msbuild@v2 - name: Install libraries run: | + where vcpkg vcpkg install gtest curl zlib brotli choco install openssl - name: Configure CMake for Release - run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_INSTALLATION_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - name: Build with CMake run: cmake --build build --config Release - name: Run tests with CTest From f4466fcb640ca9d3b4f540e4eaac2f384ba4b89e Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 00:58:00 -0500 Subject: [PATCH 07/11] Update test.yaml --- .github/workflows/test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9f8c1bb9c4..2f798dc23c 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -43,14 +43,14 @@ jobs: uses: microsoft/setup-msbuild@v2 - name: Install libraries run: | - where vcpkg vcpkg install gtest curl zlib brotli choco install openssl - name: Configure CMake for Release - run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE={{ .env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - name: Build with CMake run: cmake --build build --config Release - name: Run tests with CTest run: ctest --output-on-failure --test-dir build -C Release env: + VCPKG_ROOT: "C:/vcpkg" VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" From c5d811c61e1c4f81724e1364931b02e8c0016a31 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 01:21:11 -0500 Subject: [PATCH 08/11] Update test.yaml --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2f798dc23c..9294f97a0b 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -46,7 +46,7 @@ jobs: vcpkg install gtest curl zlib brotli choco install openssl - name: Configure CMake for Release - run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE={{ .env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE={{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - name: Build with CMake run: cmake --build build --config Release - name: Run tests with CTest From fbb86ba9096ef2f3686de8a6eb302b3119600a73 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 01:26:21 -0500 Subject: [PATCH 09/11] Update test.yaml --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 9294f97a0b..d58b49407a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -46,7 +46,7 @@ jobs: vcpkg install gtest curl zlib brotli choco install openssl - name: Configure CMake for Release - run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE={{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - name: Build with CMake run: cmake --build build --config Release - name: Run tests with CTest From 3e406efb53c98f80c97d32a7604d5ed038f33f97 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 01:37:33 -0500 Subject: [PATCH 10/11] Update test.yaml --- .github/workflows/test.yaml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d58b49407a..3d84808c1a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,7 +11,7 @@ jobs: - name: install libraries run: sudo apt-get update && sudo apt-get install -y libbrotli-dev libcurl4-openssl-dev - name: build and run tests - run: cd test && make -j4 + run: cd test && make - name: run fuzz test target run: cd test && make fuzz_test @@ -21,8 +21,9 @@ jobs: - name: checkout uses: actions/checkout@v4 - name: build and run tests - run: | - cd test && make -j2 + run: cd test && make + - name: run fuzz test target + run: cd test && make fuzz_test windows: runs-on: windows-latest @@ -39,18 +40,26 @@ jobs: script: | core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || ''); core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || ''); - - name: setup msbuild on windows + - name: Setup msbuild on windows uses: microsoft/setup-msbuild@v2 - name: Install libraries run: | vcpkg install gtest curl zlib brotli choco install openssl - - name: Configure CMake for Release + + - name: Configure CMake with SSL run: cmake -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON - - name: Build with CMake + - name: Build with with SSL run: cmake --build build --config Release - - name: Run tests with CTest + - name: Run tests with SSL run: ctest --output-on-failure --test-dir build -C Release + + - name: Configure CMake without SSL + run: cmake -B build-no-ssl -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake -DHTTPLIB_TEST=ON -DHTTPLIB_REQUIRE_OPENSSL=ON -DHTTPLIB_REQUIRE_ZLIB=ON -DHTTPLIB_REQUIRE_BROTLI=ON + - name: Build without SSL + run: cmake --build build-no-ssl --config Release + - name: Run tests without SSL + run: ctest --output-on-failure --test-dir build-no-ssl -C Release env: VCPKG_ROOT: "C:/vcpkg" VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite" From 388064fc22cc8a98e23e0fc10d7ea0df3d6dcb47 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sat, 16 Nov 2024 01:44:43 -0500 Subject: [PATCH 11/11] Fix #1980 --- httplib.h | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/httplib.h b/httplib.h index e50ad45613..f3835ee330 100644 --- a/httplib.h +++ b/httplib.h @@ -1582,6 +1582,9 @@ class ClientImpl { bool send_(Request &req, Response &res, Error &error); Result send_(Request &&req); +#ifdef CPPHTTPLIB_OPENSSL_SUPPORT + bool is_ssl_peer_could_be_closed(SSL *ssl) const; +#endif socket_t create_client_socket(Error &error) const; bool read_response_line(Stream &strm, const Request &req, Response &res) const; @@ -7415,6 +7418,14 @@ inline bool ClientImpl::send(Request &req, Response &res, Error &error) { return ret; } +#ifdef CPPHTTPLIB_OPENSSL_SUPPORT +inline bool ClientImpl::is_ssl_peer_could_be_closed(SSL *ssl) const { + char buf[1]; + return !SSL_peek(ssl, buf, 1) && + SSL_get_error(ssl, 0) == SSL_ERROR_ZERO_RETURN; +} +#endif + inline bool ClientImpl::send_(Request &req, Response &res, Error &error) { { std::lock_guard guard(socket_mutex_); @@ -7426,6 +7437,15 @@ inline bool ClientImpl::send_(Request &req, Response &res, Error &error) { auto is_alive = false; if (socket_.is_open()) { is_alive = detail::is_socket_alive(socket_.sock); + +#ifdef CPPHTTPLIB_OPENSSL_SUPPORT + if (is_alive && is_ssl()) { + if (is_ssl_peer_could_be_closed(socket_.ssl)) { + is_alive = false; + } + } +#endif + if (!is_alive) { // Attempt to avoid sigpipe by shutting down nongracefully if it seems // like the other side has already closed the connection Also, there @@ -7922,9 +7942,7 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req, if (is_ssl()) { auto is_proxy_enabled = !proxy_host_.empty() && proxy_port_ != -1; if (!is_proxy_enabled) { - char buf[1]; - if (SSL_peek(socket_.ssl, buf, 1) == 0 && - SSL_get_error(socket_.ssl, 0) == SSL_ERROR_ZERO_RETURN) { + if (is_ssl_peer_could_be_closed(socket_.ssl)) { error = Error::SSLPeerCouldBeClosed_; return false; }