test.yaml 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. name: test
  2. on:
  3. push:
  4. pull_request:
  5. workflow_dispatch:
  6. inputs:
  7. gtest_filter:
  8. description: 'Google Test filter'
  9. test_linux:
  10. description: 'Test on Linux'
  11. type: boolean
  12. default: true
  13. test_macos:
  14. description: 'Test on MacOS'
  15. type: boolean
  16. default: true
  17. test_windows:
  18. description: 'Test on Windows'
  19. type: boolean
  20. default: true
  21. concurrency:
  22. group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
  23. cancel-in-progress: true
  24. env:
  25. # Exclude *_Online tests by default — they hit external services and flake on
  26. # CI runners. Run with workflow_dispatch + a custom filter to include them.
  27. GTEST_FILTER: ${{ github.event.inputs.gtest_filter || '-*_Online' }}
  28. jobs:
  29. style-check:
  30. # Uses the macOS runner's pre-installed Homebrew so clang-format tracks
  31. # whatever version `brew install clang-format` currently resolves to on
  32. # the maintainer's own Mac, instead of a version pinned in this file.
  33. runs-on: macos-latest
  34. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
  35. continue-on-error: true
  36. steps:
  37. - name: checkout
  38. uses: actions/checkout@v4
  39. - name: install clang-format
  40. run: |
  41. brew update
  42. brew install clang-format coreutils
  43. - name: run style check
  44. run: |
  45. clang-format --version
  46. cd test && make style_check
  47. build-and-test-on-32bit:
  48. runs-on: ubuntu-latest
  49. if: >
  50. (github.event_name == 'push') ||
  51. (github.event_name == 'pull_request' &&
  52. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  53. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  54. strategy:
  55. matrix:
  56. config:
  57. - arch_flags: -m32
  58. arch_suffix: :i386
  59. name: (32-bit)
  60. steps:
  61. - name: checkout
  62. uses: actions/checkout@v4
  63. - name: install libraries
  64. run: |
  65. sudo dpkg --add-architecture i386
  66. sudo apt-get update
  67. sudo apt-get install -y libc6-dev${{ matrix.config.arch_suffix }} libstdc++-13-dev${{ matrix.config.arch_suffix }} \
  68. libssl-dev${{ matrix.config.arch_suffix }} libcurl4-openssl-dev${{ matrix.config.arch_suffix }} \
  69. zlib1g-dev${{ matrix.config.arch_suffix }} libbrotli-dev${{ matrix.config.arch_suffix }} \
  70. libzstd-dev${{ matrix.config.arch_suffix }}
  71. - name: build and run tests
  72. run: cd test && make test EXTRA_CXXFLAGS="${{ matrix.config.arch_flags }}"
  73. ubuntu:
  74. runs-on: ubuntu-latest
  75. if: >
  76. (github.event_name == 'push') ||
  77. (github.event_name == 'pull_request' &&
  78. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  79. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  80. strategy:
  81. fail-fast: false
  82. matrix:
  83. tls_backend: [openssl, mbedtls, wolfssl]
  84. name: ubuntu (${{ matrix.tls_backend }})
  85. steps:
  86. - name: checkout
  87. uses: actions/checkout@v4
  88. - name: install common libraries
  89. run: |
  90. sudo apt-get update
  91. sudo apt-get install -y libcurl4-openssl-dev zlib1g-dev libbrotli-dev libzstd-dev
  92. - name: install OpenSSL
  93. if: matrix.tls_backend == 'openssl'
  94. run: sudo apt-get install -y libssl-dev
  95. - name: install Mbed TLS
  96. if: matrix.tls_backend == 'mbedtls'
  97. run: sudo apt-get install -y libmbedtls-dev
  98. - name: install wolfSSL
  99. if: matrix.tls_backend == 'wolfssl'
  100. run: sudo apt-get install -y libwolfssl-dev
  101. - name: build and run tests (OpenSSL)
  102. if: matrix.tls_backend == 'openssl'
  103. run: cd test && make test_split && make test_openssl_parallel
  104. env:
  105. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  106. - name: build and run tests (Mbed TLS)
  107. if: matrix.tls_backend == 'mbedtls'
  108. run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
  109. - name: build and run tests (wolfSSL)
  110. if: matrix.tls_backend == 'wolfssl'
  111. run: cd test && make test_split_wolfssl && make test_wolfssl_parallel
  112. - name: run fuzz test target
  113. if: matrix.tls_backend == 'openssl'
  114. run: cd test && make fuzz_test
  115. - name: build and run WebSocket heartbeat test
  116. if: matrix.tls_backend == 'openssl'
  117. run: cd test && make test_websocket_heartbeat && ./test_websocket_heartbeat
  118. - name: build and run WebSocket TLS thread safety test
  119. if: matrix.tls_backend == 'openssl'
  120. run: cd test && make test_websocket_thread_safety && ./test_websocket_thread_safety
  121. - name: build and run ThreadPool test
  122. run: cd test && make test_thread_pool && ./test_thread_pool
  123. # Ubuntu 26.04's apt ships Mbed TLS 3.6, giving 3.x coverage that
  124. # ubuntu-latest (24.04 = 2.28) and macOS (Homebrew = 4.x) no longer provide.
  125. # Uses the 26.04 public-preview image; fold into the main ubuntu matrix once
  126. # ubuntu-latest moves to 26.04.
  127. ubuntu-2604-mbedtls:
  128. runs-on: ubuntu-26.04
  129. if: >
  130. (github.event_name == 'push') ||
  131. (github.event_name == 'pull_request' &&
  132. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  133. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  134. name: ubuntu-26.04 (mbedtls 3.x)
  135. steps:
  136. - name: checkout
  137. uses: actions/checkout@v4
  138. - name: install common libraries
  139. run: |
  140. sudo apt-get update
  141. sudo apt-get install -y libcurl4-openssl-dev zlib1g-dev libbrotli-dev libzstd-dev
  142. - name: install Mbed TLS
  143. run: sudo apt-get install -y libmbedtls-dev
  144. - name: build and run tests (Mbed TLS)
  145. run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
  146. # BoringSSL is Google's fork of OpenSSL. It has no API stability guarantee
  147. # and is not packaged by distros, so we build it from source. cpp-httplib
  148. # treats it as an OpenSSL backend variant via the OPENSSL_IS_BORINGSSL
  149. # macro (see httplib.h). This job is best-effort: continue-on-error keeps
  150. # upstream API drift from blocking PRs while still surfacing breakage.
  151. ubuntu-boringssl:
  152. runs-on: ubuntu-latest
  153. if: >
  154. (github.event_name == 'push') ||
  155. (github.event_name == 'pull_request' &&
  156. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  157. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  158. continue-on-error: true
  159. name: ubuntu (boringssl, best-effort)
  160. env:
  161. # Tracking HEAD keeps us honest about upstream churn. If breakage
  162. # becomes routine, replace HEAD with a 40-char commit SHA; the
  163. # resolve step uses the SHA directly when it matches that shape.
  164. BORINGSSL_REF: HEAD
  165. BORINGSSL_PREFIX: ${{ github.workspace }}/boringssl-install
  166. steps:
  167. - name: checkout
  168. uses: actions/checkout@v4
  169. - name: install common libraries
  170. run: |
  171. sudo apt-get update
  172. sudo apt-get install -y libcurl4-openssl-dev zlib1g-dev libbrotli-dev libzstd-dev
  173. - name: resolve BoringSSL commit
  174. id: boringssl-rev
  175. # Accept either a ref name (resolved via git ls-remote) or a full
  176. # 40-char SHA used directly. ls-remote does not list arbitrary
  177. # commit SHAs, so pinning requires the second path.
  178. run: |
  179. if [[ "${BORINGSSL_REF}" =~ ^[0-9a-f]{40}$ ]]; then
  180. sha="${BORINGSSL_REF}"
  181. echo "Using pinned BoringSSL SHA: ${sha}"
  182. else
  183. sha=$(git ls-remote https://boringssl.googlesource.com/boringssl "${BORINGSSL_REF}" | awk '{print $1}')
  184. if [ -z "$sha" ]; then
  185. echo "Failed to resolve BoringSSL ref ${BORINGSSL_REF}" >&2
  186. exit 1
  187. fi
  188. echo "Resolved ${BORINGSSL_REF} -> ${sha}"
  189. fi
  190. echo "sha=${sha}" >> "$GITHUB_OUTPUT"
  191. - name: cache BoringSSL build
  192. id: boringssl-cache
  193. uses: actions/cache@v4
  194. with:
  195. path: ${{ env.BORINGSSL_PREFIX }}
  196. key: boringssl-${{ runner.os }}-${{ steps.boringssl-rev.outputs.sha }}
  197. - name: build BoringSSL
  198. if: steps.boringssl-cache.outputs.cache-hit != 'true'
  199. run: |
  200. set -e
  201. git clone https://boringssl.googlesource.com/boringssl boringssl
  202. cd boringssl
  203. git checkout "${{ steps.boringssl-rev.outputs.sha }}"
  204. # GCC 15 reports a false -Wstringop-overflow in BoringSSL's Keccak
  205. # code, which its -Werror makes fatal. Clang is its primary compiler.
  206. cmake -S . -B build \
  207. -DCMAKE_C_COMPILER=clang \
  208. -DCMAKE_CXX_COMPILER=clang++ \
  209. -DCMAKE_BUILD_TYPE=Release \
  210. -DBUILD_SHARED_LIBS=OFF \
  211. -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  212. -DCMAKE_INSTALL_PREFIX="${BORINGSSL_PREFIX}"
  213. cmake --build build -j"$(nproc)" --target install
  214. - name: build and run tests (BoringSSL)
  215. # Override OPENSSL_SUPPORT to point the existing OpenSSL Makefile path
  216. # at BoringSSL's prefix. BoringSSL defines OPENSSL_IS_BORINGSSL in
  217. # <openssl/base.h>, which httplib.h and test.cc use to switch on API
  218. # differences (e.g. SAN-only hostname verification, no CN fallback).
  219. #
  220. # BoringSSL's public headers (<openssl/stack.h>) use std::enable_if_t,
  221. # so consumers must compile with C++14 or later. cpp-httplib itself
  222. # supports C++11, but anyone pairing it with BoringSSL inherits this
  223. # constraint. EXTRA_CXXFLAGS appends after the Makefile's -std=c++11
  224. # and the later flag wins.
  225. run: |
  226. cd test
  227. BORINGSSL_FLAGS="-DCPPHTTPLIB_OPENSSL_SUPPORT -I${BORINGSSL_PREFIX}/include -L${BORINGSSL_PREFIX}/lib -lssl -lcrypto -lpthread"
  228. make test_split OPENSSL_SUPPORT="${BORINGSSL_FLAGS}" EXTRA_CXXFLAGS="-std=c++17"
  229. make test_openssl_parallel OPENSSL_SUPPORT="${BORINGSSL_FLAGS}" EXTRA_CXXFLAGS="-std=c++17"
  230. env:
  231. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  232. # macOS counterpart of the BoringSSL job. Same best-effort posture; the
  233. # extra framework links cover the macOS Keychain integration that
  234. # httplib.h auto-enables for any TLS backend on macOS.
  235. macos-boringssl:
  236. runs-on: macos-latest
  237. if: >
  238. (github.event_name == 'push') ||
  239. (github.event_name == 'pull_request' &&
  240. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  241. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
  242. continue-on-error: true
  243. name: macos (boringssl, best-effort)
  244. env:
  245. BORINGSSL_REF: HEAD
  246. BORINGSSL_PREFIX: ${{ github.workspace }}/boringssl-install
  247. steps:
  248. - name: checkout
  249. uses: actions/checkout@v4
  250. - name: resolve BoringSSL commit
  251. id: boringssl-rev
  252. # Accept either a ref name (resolved via git ls-remote) or a full
  253. # 40-char SHA used directly. ls-remote does not list arbitrary
  254. # commit SHAs, so pinning requires the second path.
  255. run: |
  256. if [[ "${BORINGSSL_REF}" =~ ^[0-9a-f]{40}$ ]]; then
  257. sha="${BORINGSSL_REF}"
  258. echo "Using pinned BoringSSL SHA: ${sha}"
  259. else
  260. sha=$(git ls-remote https://boringssl.googlesource.com/boringssl "${BORINGSSL_REF}" | awk '{print $1}')
  261. if [ -z "$sha" ]; then
  262. echo "Failed to resolve BoringSSL ref ${BORINGSSL_REF}" >&2
  263. exit 1
  264. fi
  265. echo "Resolved ${BORINGSSL_REF} -> ${sha}"
  266. fi
  267. echo "sha=${sha}" >> "$GITHUB_OUTPUT"
  268. - name: cache BoringSSL build
  269. id: boringssl-cache
  270. uses: actions/cache@v4
  271. with:
  272. path: ${{ env.BORINGSSL_PREFIX }}
  273. key: boringssl-${{ runner.os }}-${{ steps.boringssl-rev.outputs.sha }}
  274. - name: build BoringSSL
  275. if: steps.boringssl-cache.outputs.cache-hit != 'true'
  276. run: |
  277. set -e
  278. git clone https://boringssl.googlesource.com/boringssl boringssl
  279. cd boringssl
  280. git checkout "${{ steps.boringssl-rev.outputs.sha }}"
  281. cmake -S . -B build \
  282. -DCMAKE_BUILD_TYPE=Release \
  283. -DBUILD_SHARED_LIBS=OFF \
  284. -DCMAKE_POSITION_INDEPENDENT_CODE=ON \
  285. -DCMAKE_INSTALL_PREFIX="${BORINGSSL_PREFIX}"
  286. cmake --build build -j"$(sysctl -n hw.ncpu)" --target install
  287. - name: build and run tests (BoringSSL)
  288. run: |
  289. cd test
  290. # CoreFoundation/Security frameworks satisfy the Keychain integration
  291. # auto-enabled in httplib.h for macOS TLS builds.
  292. BORINGSSL_FLAGS="-DCPPHTTPLIB_OPENSSL_SUPPORT -I${BORINGSSL_PREFIX}/include -L${BORINGSSL_PREFIX}/lib -lssl -lcrypto -framework CoreFoundation -framework Security"
  293. make test_split OPENSSL_SUPPORT="${BORINGSSL_FLAGS}" EXTRA_CXXFLAGS="-std=c++17"
  294. make test_openssl_parallel OPENSSL_SUPPORT="${BORINGSSL_FLAGS}" EXTRA_CXXFLAGS="-std=c++17"
  295. env:
  296. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  297. # Reproducer for https://github.com/yhirose/cpp-httplib/issues/2431.
  298. # On Linux/glibc, getaddrinfo_with_timeout() schedules an asynchronous
  299. # DNS lookup with getaddrinfo_a(GAI_NOWAIT) using a stack-local gaicb.
  300. # When gai_suspend() hits the connection timeout, gai_cancel() is called
  301. # but does not block; the resolver worker can later write back into the
  302. # destroyed stack frame. To make the worker actually reach that write,
  303. # the test job runs a loopback UDP responder (test/dns_test_fixture.py)
  304. # that delays its reply past the test's 1s timeout, and uses an iptables
  305. # NAT rule so glibc's lookups land on that fixture instead of a real
  306. # nameserver. With ASAN's detect_stack_use_after_return enabled, the
  307. # late write-back is reported as a stack-use-after-return.
  308. issue-2431-repro:
  309. runs-on: ubuntu-latest
  310. if: >
  311. (github.event_name == 'push') ||
  312. (github.event_name == 'pull_request' &&
  313. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  314. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  315. name: issue-2431 repro (Linux + ASAN)
  316. # Loose, because apt on the runner mirror can crawl for minutes; the test
  317. # step has its own tight limit.
  318. timeout-minutes: 15
  319. env:
  320. DNS_FIXTURE_PORT: "15353"
  321. DNS_FIXTURE_DELAY: "3"
  322. steps:
  323. - name: checkout
  324. uses: actions/checkout@v4
  325. - name: install libraries
  326. run: |
  327. sudo apt-get update
  328. sudo apt-get install -y libssl-dev zlib1g-dev libbrotli-dev \
  329. libzstd-dev libcurl4-openssl-dev iptables util-linux iproute2
  330. - name: start loopback DNS test fixture
  331. run: |
  332. # Force glibc through its DNS code path: Ubuntu's default
  333. # nsswitch short-circuits to NOTFOUND through mdns4_minimal,
  334. # which would skip the buggy code entirely.
  335. sudo sed -i 's/^hosts:.*/hosts: dns/' /etc/nsswitch.conf
  336. # Run the loopback fixture (delayed UDP responder).
  337. python3 test/dns_test_fixture.py "$DNS_FIXTURE_PORT" "$DNS_FIXTURE_DELAY" \
  338. >/tmp/dns_fixture.log 2>&1 &
  339. echo $! | sudo tee /tmp/dns_fixture.pid >/dev/null
  340. # Wait for the fixture to start listening.
  341. for _ in $(seq 1 50); do
  342. if ss -lun "( sport = :$DNS_FIXTURE_PORT )" | grep -q ":$DNS_FIXTURE_PORT"; then
  343. break
  344. fi
  345. sleep 0.1
  346. done
  347. ss -lun "( sport = :$DNS_FIXTURE_PORT )" | grep -q ":$DNS_FIXTURE_PORT" \
  348. || { echo "fixture failed to start"; cat /tmp/dns_fixture.log; exit 1; }
  349. # Send the test process's DNS lookups to the loopback fixture.
  350. # NAT only the local OUTPUT chain; conntrack handles the reply path.
  351. sudo iptables -t nat -I OUTPUT -p udp --dport 53 \
  352. -j REDIRECT --to-port "$DNS_FIXTURE_PORT"
  353. # Sanity check: a query must take at least the fixture delay
  354. # and resolve to NXDOMAIN (proving traffic reaches the fixture).
  355. start=$(date +%s)
  356. getent hosts unresolvable-host.invalid >/dev/null 2>&1 || true
  357. elapsed=$(( $(date +%s) - start ))
  358. if [ "$elapsed" -lt 2 ]; then
  359. echo "ERROR: lookup returned in ${elapsed}s; fixture not in path" >&2
  360. exit 1
  361. fi
  362. echo "[ok] DNS lookups are routed to the test fixture (took ${elapsed}s)"
  363. - name: build test binary
  364. run: cd test && make test
  365. - name: run GetAddrInfoAsyncCancelTest
  366. # A normal run takes about 80s.
  367. timeout-minutes: 3
  368. run: |
  369. cd test
  370. ARCH=$(uname -m)
  371. CPPHTTPLIB_TEST_ISSUE_2431=1 \
  372. ASAN_OPTIONS=detect_stack_use_after_return=1 \
  373. LSAN_OPTIONS=suppressions=lsan_suppressions.txt \
  374. setarch "$ARCH" -R \
  375. ./test --gtest_filter='GetAddrInfoAsyncCancelTest.*'
  376. - name: tear down test fixture
  377. if: always()
  378. run: |
  379. sudo iptables -t nat -F OUTPUT || true
  380. if [ -f /tmp/dns_fixture.pid ]; then
  381. sudo kill "$(cat /tmp/dns_fixture.pid)" 2>/dev/null || true
  382. fi
  383. macos:
  384. runs-on: macos-latest
  385. if: >
  386. (github.event_name == 'push') ||
  387. (github.event_name == 'pull_request' &&
  388. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  389. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
  390. strategy:
  391. fail-fast: false
  392. matrix:
  393. tls_backend: [openssl, mbedtls, wolfssl]
  394. name: macos (${{ matrix.tls_backend }})
  395. steps:
  396. - name: checkout
  397. uses: actions/checkout@v4
  398. - name: install Mbed TLS
  399. if: matrix.tls_backend == 'mbedtls'
  400. run: brew install mbedtls
  401. - name: install wolfSSL
  402. if: matrix.tls_backend == 'wolfssl'
  403. run: brew install wolfssl
  404. - name: build and run tests (OpenSSL)
  405. if: matrix.tls_backend == 'openssl'
  406. run: cd test && make test_split && make test_openssl_parallel
  407. env:
  408. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  409. - name: build and run tests (Mbed TLS)
  410. if: matrix.tls_backend == 'mbedtls'
  411. run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
  412. - name: build and run tests (wolfSSL)
  413. if: matrix.tls_backend == 'wolfssl'
  414. run: cd test && make test_split_wolfssl && make test_wolfssl_parallel
  415. - name: run fuzz test target
  416. if: matrix.tls_backend == 'openssl'
  417. run: cd test && make fuzz_test
  418. - name: build and run WebSocket heartbeat test
  419. if: matrix.tls_backend == 'openssl'
  420. run: cd test && make test_websocket_heartbeat && ./test_websocket_heartbeat
  421. - name: build and run WebSocket TLS thread safety test
  422. if: matrix.tls_backend == 'openssl'
  423. run: cd test && make test_websocket_thread_safety && ./test_websocket_thread_safety
  424. - name: build and run ThreadPool test
  425. run: cd test && make test_thread_pool && ./test_thread_pool
  426. ios-parse-check:
  427. runs-on: macos-latest
  428. if: >
  429. (github.event_name == 'push') ||
  430. (github.event_name == 'pull_request' &&
  431. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  432. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
  433. name: ios header parse check (not officially supported)
  434. steps:
  435. - name: checkout
  436. uses: actions/checkout@v4
  437. - name: install OpenSSL headers
  438. run: brew install openssl@3
  439. - name: verify header parses on iOS target
  440. run: |
  441. IOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path)
  442. OPENSSL_INC=$(brew --prefix openssl@3)/include
  443. echo "Using iOS SDK: $IOS_SDK"
  444. echo '#include "httplib.h"' | clang++ \
  445. -isysroot "$IOS_SDK" \
  446. -target arm64-apple-ios16.0 \
  447. -std=c++11 \
  448. -DCPPHTTPLIB_OPENSSL_SUPPORT \
  449. -I"$OPENSSL_INC" \
  450. -I. -Wall -Wextra \
  451. -fsyntax-only -x c++ -
  452. - name: verify CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN is rejected on iOS
  453. run: |
  454. IOS_SDK=$(xcrun --sdk iphoneos --show-sdk-path)
  455. OPENSSL_INC=$(brew --prefix openssl@3)/include
  456. out=$(echo '#include "httplib.h"' | clang++ \
  457. -isysroot "$IOS_SDK" \
  458. -target arm64-apple-ios16.0 \
  459. -std=c++11 \
  460. -DCPPHTTPLIB_OPENSSL_SUPPORT \
  461. -DCPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN \
  462. -I"$OPENSSL_INC" \
  463. -I. \
  464. -fsyntax-only -x c++ - 2>&1 || true)
  465. if echo "$out" | grep -q "only supported on macOS"; then
  466. echo "OK: #error fired as expected"
  467. else
  468. echo "FAIL: expected #error did not fire"
  469. echo "--- compiler output ---"
  470. echo "$out"
  471. exit 1
  472. fi
  473. windows:
  474. runs-on: windows-latest
  475. permissions:
  476. contents: read
  477. if: >
  478. (github.event_name == 'push') ||
  479. (github.event_name == 'pull_request' &&
  480. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  481. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_windows == 'true')
  482. strategy:
  483. fail-fast: false
  484. matrix:
  485. config:
  486. - with_ssl: false
  487. compiled: false
  488. run_tests: true
  489. name: without SSL
  490. - with_ssl: true
  491. compiled: false
  492. run_tests: true
  493. name: with SSL
  494. - with_ssl: false
  495. compiled: true
  496. run_tests: false
  497. name: compiled
  498. name: windows ${{ matrix.config.name }}
  499. steps:
  500. - name: Prepare Git for Checkout on Windows
  501. run: |
  502. git config --global core.autocrlf false
  503. git config --global core.eol lf
  504. - name: Checkout
  505. uses: actions/checkout@v4
  506. - name: Export GitHub Actions cache environment variables
  507. uses: actions/github-script@v7
  508. with:
  509. script: |
  510. core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
  511. core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
  512. - name: Setup msbuild on windows
  513. uses: microsoft/setup-msbuild@v2
  514. - name: Cache vcpkg packages
  515. id: vcpkg-cache
  516. uses: actions/cache@v4
  517. with:
  518. path: C:/vcpkg/installed
  519. key: vcpkg-installed-windows-gtest-curl-zlib-brotli-zstd
  520. - name: Install vcpkg dependencies
  521. if: steps.vcpkg-cache.outputs.cache-hit != 'true'
  522. run: vcpkg install gtest curl zlib brotli zstd
  523. - name: Install OpenSSL
  524. if: ${{ matrix.config.with_ssl }}
  525. shell: pwsh
  526. run: |
  527. # Chocolatey's openssl package hardcodes a versioned slproweb URL, and
  528. # slproweb keeps only the newest build of each branch. The package
  529. # therefore 404s on every OpenSSL release until someone respins it.
  530. # Read slproweb's own manifest instead: it is updated at the same time
  531. # as the downloads it points at, so the URL is always live.
  532. $ErrorActionPreference = 'Stop'
  533. $ProgressPreference = 'SilentlyContinue' # Invoke-WebRequest is slow with it
  534. $manifest = 'https://raw.githubusercontent.com/slproweb/opensslhashes/master/win32_openssl_hashes.json'
  535. $entry = (Invoke-RestMethod $manifest).files.PSObject.Properties.Value |
  536. Where-Object {
  537. $_.bits -eq 64 -and $_.arch -eq 'INTEL' -and
  538. -not $_.light -and $_.installer -eq 'exe' -and $_.basever -like '4.*'
  539. } |
  540. Sort-Object { [version]$_.basever } | Select-Object -Last 1
  541. if (-not $entry) { throw 'No 64-bit OpenSSL 4.x installer found in the manifest' }
  542. Write-Host "Installing OpenSSL $($entry.basever) from $($entry.url)"
  543. $installer = Join-Path $env:RUNNER_TEMP 'Win64OpenSSL.exe'
  544. Invoke-WebRequest $entry.url -OutFile $installer
  545. $actual = (Get-FileHash $installer -Algorithm SHA512).Hash.ToLower()
  546. if ($actual -ne $entry.sha512.ToLower()) {
  547. throw "SHA512 mismatch: expected $($entry.sha512), got $actual"
  548. }
  549. # Same silent flags the Chocolatey package used. The installer is Inno
  550. # Setup, so /DIR pins the location CMake already looks in. The inner
  551. # quotes matter: ArgumentList joins on spaces, so an unquoted /DIR
  552. # would install to C:\Program and only fail later, at load time.
  553. $dir = 'C:\Program Files\OpenSSL'
  554. $proc = Start-Process $installer -Wait -PassThru -ArgumentList `
  555. '/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART', '/SP-', "/DIR=`"$dir`""
  556. if ($proc.ExitCode -ne 0) { throw "Installer exited with $($proc.ExitCode)" }
  557. # Catch a misplaced install here rather than at link or load time.
  558. if (-not (Test-Path "$dir\lib\VC\x64\MD\libcrypto.lib")) {
  559. throw "OpenSSL import libraries missing under $dir"
  560. }
  561. if (-not (Get-ChildItem "$dir\bin\libcrypto-*.dll" -ErrorAction SilentlyContinue)) {
  562. throw "OpenSSL runtime DLLs missing under $dir\bin"
  563. }
  564. "$dir\bin" | Out-File $env:GITHUB_PATH -Append -Encoding utf8
  565. "OPENSSL_CONF=$dir\bin\openssl.cfg" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
  566. - name: Configure CMake ${{ matrix.config.name }}
  567. run: >
  568. cmake -B build -S .
  569. -DCMAKE_BUILD_TYPE=Release
  570. -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
  571. -DHTTPLIB_TEST=ON
  572. -DHTTPLIB_COMPILE=${{ matrix.config.compiled && 'ON' || 'OFF' }}
  573. -DHTTPLIB_USE_OPENSSL_IF_AVAILABLE=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
  574. -DHTTPLIB_REQUIRE_ZLIB=ON
  575. -DHTTPLIB_REQUIRE_BROTLI=ON
  576. -DHTTPLIB_REQUIRE_ZSTD=ON
  577. -DHTTPLIB_REQUIRE_OPENSSL=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
  578. - name: Build ${{ matrix.config.name }}
  579. run: cmake --build build --config Release -- /v:m /clp:ShowCommandLine
  580. - name: Run tests ${{ matrix.config.name }}
  581. if: ${{ matrix.config.run_tests }}
  582. shell: pwsh
  583. working-directory: build/test
  584. run: |
  585. $shards = 4
  586. $procs = @()
  587. for ($i = 0; $i -lt $shards; $i++) {
  588. $log = "shard_${i}.log"
  589. $procs += Start-Process -FilePath ./Release/httplib-test.exe `
  590. -ArgumentList "--gtest_color=yes","--gtest_filter=${{ github.event.inputs.gtest_filter || '-*_Online' }}" `
  591. -NoNewWindow -PassThru -RedirectStandardOutput $log -RedirectStandardError "${log}.err" `
  592. -Environment @{ GTEST_TOTAL_SHARDS="$shards"; GTEST_SHARD_INDEX="$i" }
  593. }
  594. $procs | Wait-Process
  595. $failed = $false
  596. for ($i = 0; $i -lt $shards; $i++) {
  597. $log = "shard_${i}.log"
  598. $proc = $procs[$i]
  599. $hasPassed = Select-String -Path $log -Pattern "\[ PASSED \]" -Quiet
  600. $hasFailed = Select-String -Path $log -Pattern "\[ FAILED \]" -Quiet
  601. if ($hasPassed -and -not $hasFailed -and $proc.ExitCode -eq 0) {
  602. $passed = (Select-String -Path $log -Pattern "\[ PASSED \]").Line
  603. Write-Host "Shard ${i}: $passed"
  604. } else {
  605. Write-Host "=== Shard $i FAILED (exit=$($proc.ExitCode)) ==="
  606. Get-Content $log
  607. if (Test-Path "${log}.err") { Get-Content "${log}.err" }
  608. $failed = $true
  609. }
  610. }
  611. if ($failed) { exit 1 }
  612. Write-Host "All shards passed."
  613. env:
  614. VCPKG_ROOT: "C:/vcpkg"
  615. VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"