Skip to content

Commit 970b528

Browse files
authored
Fix #1980
Fix #1980
1 parent 412ba04 commit 970b528

File tree

2 files changed

+53
-13
lines changed

2 files changed

+53
-13
lines changed

.github/workflows/test.yaml

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
- name: install libraries
1212
run: sudo apt-get update && sudo apt-get install -y libbrotli-dev libcurl4-openssl-dev
1313
- name: build and run tests
14-
run: cd test && make -j4
14+
run: cd test && make
1515
- name: run fuzz test target
1616
run: cd test && make fuzz_test
1717

@@ -21,23 +21,45 @@ jobs:
2121
- name: checkout
2222
uses: actions/checkout@v4
2323
- name: build and run tests
24-
run: |
25-
cd test && make -j2
24+
run: cd test && make
25+
- name: run fuzz test target
26+
run: cd test && make fuzz_test
2627

2728
windows:
2829
runs-on: windows-latest
2930
steps:
30-
- name: prepare git for checkout on windows
31+
- name: Prepare Git for Checkout on Windows
3132
run: |
3233
git config --global core.autocrlf false
3334
git config --global core.eol lf
34-
- name: checkout
35+
- name: Checkout
3536
uses: actions/checkout@v4
36-
- name: setup msbuild on windows
37+
- name: Export GitHub Actions cache environment variables
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
42+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
43+
- name: Setup msbuild on windows
3744
uses: microsoft/setup-msbuild@v2
38-
- name: make-windows
45+
- name: Install libraries
3946
run: |
40-
cd test
41-
msbuild.exe test.sln /verbosity:minimal /t:Build "/p:Configuration=Release;Platform=x64"
42-
x64\Release\test.exe
47+
vcpkg install gtest curl zlib brotli
48+
choco install openssl
49+
50+
- name: Configure CMake with SSL
51+
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
52+
- name: Build with with SSL
53+
run: cmake --build build --config Release
54+
- name: Run tests with SSL
55+
run: ctest --output-on-failure --test-dir build -C Release
4356

57+
- name: Configure CMake without SSL
58+
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
59+
- name: Build without SSL
60+
run: cmake --build build-no-ssl --config Release
61+
- name: Run tests without SSL
62+
run: ctest --output-on-failure --test-dir build-no-ssl -C Release
63+
env:
64+
VCPKG_ROOT: "C:/vcpkg"
65+
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

httplib.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,9 @@ class ClientImpl {
15821582
bool send_(Request &req, Response &res, Error &error);
15831583
Result send_(Request &&req);
15841584

1585+
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
1586+
bool is_ssl_peer_could_be_closed(SSL *ssl) const;
1587+
#endif
15851588
socket_t create_client_socket(Error &error) const;
15861589
bool read_response_line(Stream &strm, const Request &req,
15871590
Response &res) const;
@@ -7415,6 +7418,14 @@ inline bool ClientImpl::send(Request &req, Response &res, Error &error) {
74157418
return ret;
74167419
}
74177420

7421+
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
7422+
inline bool ClientImpl::is_ssl_peer_could_be_closed(SSL *ssl) const {
7423+
char buf[1];
7424+
return !SSL_peek(ssl, buf, 1) &&
7425+
SSL_get_error(ssl, 0) == SSL_ERROR_ZERO_RETURN;
7426+
}
7427+
#endif
7428+
74187429
inline bool ClientImpl::send_(Request &req, Response &res, Error &error) {
74197430
{
74207431
std::lock_guard<std::mutex> guard(socket_mutex_);
@@ -7426,6 +7437,15 @@ inline bool ClientImpl::send_(Request &req, Response &res, Error &error) {
74267437
auto is_alive = false;
74277438
if (socket_.is_open()) {
74287439
is_alive = detail::is_socket_alive(socket_.sock);
7440+
7441+
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
7442+
if (is_alive && is_ssl()) {
7443+
if (is_ssl_peer_could_be_closed(socket_.ssl)) {
7444+
is_alive = false;
7445+
}
7446+
}
7447+
#endif
7448+
74297449
if (!is_alive) {
74307450
// Attempt to avoid sigpipe by shutting down nongracefully if it seems
74317451
// like the other side has already closed the connection Also, there
@@ -7922,9 +7942,7 @@ inline bool ClientImpl::process_request(Stream &strm, Request &req,
79227942
if (is_ssl()) {
79237943
auto is_proxy_enabled = !proxy_host_.empty() && proxy_port_ != -1;
79247944
if (!is_proxy_enabled) {
7925-
char buf[1];
7926-
if (SSL_peek(socket_.ssl, buf, 1) == 0 &&
7927-
SSL_get_error(socket_.ssl, 0) == SSL_ERROR_ZERO_RETURN) {
7945+
if (is_ssl_peer_could_be_closed(socket_.ssl)) {
79287946
error = Error::SSLPeerCouldBeClosed_;
79297947
return false;
79307948
}

0 commit comments

Comments
 (0)