Websockets - #46
Merged
Merged
Conversation
Split th_router_add_route into th_router_find_or_create_segment (path resolution) and the method-slot write, so websocket route registration can reuse the trie walk without duplicating it.
- add th_ws_handler/th_ws_send/th_ws_close/th_route_ws public API, TH_ERR_BUSY, TH_CODE_SWITCHING_PROTOCOLS - th_router_resolve/th_route_consume_trail take a th_str path and a capture callback instead of a th_request*, so path resolution no longer depends on a full request - th_router_find_ws_route now takes a th_str path directly, matching resolve's new signature and letting WS route lookups skip building a th_request entirely
- add SHA-1, Base64, and RFC 6455 handshake/accept-key computation - wire WS upgrade into th_http: 101 response on valid handshake, 426 on non-handshake requests to WS routes, hand connection off to a new th_ws instance - th_router: WS-only routes get a default GET handler so they don't 405; registering a real handler later overrides it - fix Connection header value being discarded during parsing - fix default error body reason phrase always showing "Unknown"
- th_ws_frame_parser: incremental RFC 6455 frame parser, mirrors th_request_parser's switch-based per-state dispatch - th_ws now accumulates message payloads and dispatches DATA/CLOSE events; ping/pong are discarded without reaching the handler - add TH_EPROTO system error code for protocol violations - fix: th_route_init left ws_handler uninitialized, causing th_router_add_ws_route to spuriously fail on a fresh route Sending frames is not implemented yet (th_ws_send/th_ws_close remain TH_ERR_NOSUPPORT stubs).
Renames th_ws_msg_type to th_ws_type, and adds it as a parameter to th_ws_handler so TH_WS_EVENT_DATA callers know the message's frame opcode, not just its bytes.
- th_ws_send queues header+payload into a th_ring (growable chunked ring buffer) and drains it via th_conn_send; grows on overflow instead of rejecting, capped by TH_CONFIG_WS_SEND_MAX_LEN - th_ws_frame_header_write encodes the frame header, shared so close/ping-pong replies can reuse it later - fix: th_queue's _pop left a dangling tail pointer after removing the last item
- th_ws_close queues a CLOSE frame through the normal send path; TH_WS_EVENT_CLOSE fires and the connection tears down once it drains - receiving a CLOSE now echoes one back before closing, instead of dropping the connection without completing the handshake - th_ws_send/th_ws_close return TH_ERR_INVALID_ARG once closing - fix: th_ring_chunk_write crashed on a NULL, zero-length payload (e.g. an empty CLOSE frame)
- fix typos - Remove remark that OpenSSL is slow, should be quite OK by now - Websocket support is now feature
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Codecov applies its own coverage checks independent of the uploaded XML, so examples/tests/benchmarks need to be excluded there too.
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.
Uh oh!
There was an error while loading. Please reload this page.