test.yaml 28 KB

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