Repository navigation
feat(web): WS 客户端可发送自定义 Upgrade 头 - #119
Merged
Merged
Conversation
Antruly
force-pushed
the
feat/ws-client-handshake-header
branch
from
November 27, 2026 15:11
c58b1bc to
c7196e9
Compare
新增 `uvcpp_ws_client::set_handshake_header(name, value)`,让调用方在 `connect()` 之前把 Authorization、Cookie、Origin、Sec-WebSocket-Protocol 等头写进 HTTP Upgrade 请求,不必自己手拼 101 流程。 - 名字或值含 CR/LF 时整条忽略,避免头注入; - Host、Upgrade、Connection、Sec-WebSocket-Key、Sec-WebSocket-Version、 Sec-WebSocket-Extensions 为保留头(大小写不敏感); - 同名头覆盖上一次的值,发送顺序按首次添加; - 功能测试启动裸 TCP 服务端,断言服务端真正收到的字节,覆盖普通头、 同名覆盖、保留头、CR/LF 注入、空值与 Sec-WebSocket-Protocol; - 同步更新 doc/web-ws-guide.md 与 CHANGELOG。 验证: - cmake -S . -B build-ws -G Ninja -DCMAKE_BUILD_TYPE=Release -DUVCPP_BUILD_WEB=ON -DUVCPP_WEB_WS=ON -DUVCPP_BUILD_TESTS=ON -DUVCPP_BUILD_FUNCTIONAL=ON -DUVCPP_ENABLE_OPENSSL=OFF -DUVCPP_ENABLE_ZLIB=OFF -DUVCPP_ENABLE_NGHTTP2=OFF -DUVCPP_BUILD_WEBAPP=OFF - cmake --build build-ws --target test_web_ws_client_handshake_header_func - ./build-ws/tests/functional/test_web_ws_client_handshake_header_func:全部通过 - 回归:test_web_ws_client_api_func、test_web_ws_subprotocol_func - python3 tests/tools/check_docs.py、check_doc_versions.py、 check_doc_lines.py:全过
Antruly
force-pushed
the
feat/ws-client-handshake-header
branch
from
November 27, 2026 15:34
c7196e9 to
aff8145
Compare
db-servers 档用 -DUVCPP_ENABLE_DB_SQLITE=OFF 只测 mysql/postgres/odbc, 但过滤只摘了 db_sqlite_*.cpp,orm_sqlite_func.cpp 仍被注册,并在 ctest 里以 no_driver 失败。把过滤扩展为 (db|orm)_sqlite。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
uvcpp_ws_client以前只会拼固定的 Upgrade 头,Authorization/Cookie/Origin/Sec-WebSocket-Protocol这类目标连不上;现在新增set_handshake_header(name, value),在connect()前追加自定义头。Why
uvscope 的后端 WebSocket 调试与反向代理 WS 透传需要携带这些头,但
uvcpp_ws_client没有公开入口,只能绕到on_upgrade自己拼 101。这个提交把入口补在一层,行为与 uvscope 目前携带的 patch 0005 一致,合并后该补丁可以删除。
规则:
Host、Upgrade、Connection、Sec-WebSocket-Key、Sec-WebSocket-Version、Sec-WebSocket-Extensions为保留头(大小写不敏感);How it was checked
python3 tests/tools/check_docs.py→ 全过(3 条判据)python3 tests/tools/check_doc_versions.py→ 全过(4 处版本串 == 1.12.0)python3 tests/tools/check_doc_lines.py→ 全过(5 条判据;已刷新doc_line_refs.lock)python3 tests/tools/check_ci_layout.py(未改.github/,不需要)输出:
100% tests passed, 0 tests failed out of 3。新增用例启动裸 TCP 服务端,断言服务端真正收到的 Upgrade 字节,覆盖普通头、同名覆盖、保留头、CR/LF 注入、
空值、
Sec-WebSocket-Protocol六族。Conventions
git add -A/git commit -a。src/uvcpp/uvcpp_version.h未改(功能提交不动版本)。Additional CI fix
The
db-serversjob configures with-DUVCPP_ENABLE_DB_SQLITE=OFFbut the functional-testfilter only excluded
db_sqlite_*;orm_sqlite_func.cppwas still registered and failed withno_driver. The second commit extends the filter to(db|orm)_sqlite. The new WS test itselfpassed in that job (
130/144 ... Passed).