SignalR features: expose WebSocket handshake state and send buffer for external hosts - #336
Open
sergiovision wants to merge 2 commits into
Open
Conversation
added 2 commits
September 11, 2026 11:17
…nagement - Use 32-bit chunked XOR in MaskBuffer for fast masking/unmasking - Direct memory copy for unmasked server-to-client frames - Batch append bytes during frame header parsing instead of byte-by-byte loops - Fast base64 validation for Sec-WebSocket-Accept handshake header - Optimized Buffer.Reserve with minimum allocation floor to prevent realloc churn - Add null/empty checks for span and array appends in Buffer - Safe BodyBytes copy in HttpRequest and HttpResponse - Bump project version to 10.0.1.0
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.
Summary
WebSocketis already a self-contained handshake + framing engine (PerformServerUpgrade,PrepareReceiveFrame,PrepareSendFrame) thatWsSession/WssSessiondrive over their ownsocket. Three members it needs are
internal, which prevents reusing the engine over a stream ownedby a different HTTP host — for example an ASP.NET Core / Kestrel upgraded connection that serves
SignalR-style hub paths (
/hub/...) on the same port as a REST API, so no second WebSocket port hasto be opened and proxied.
This change also introduces significant performance and reliability optimizations for WebSocket framing, masking, and buffer management.
Changes
Expose WebSocket Engine Members for External Hosts:
WebSocket.WsHandshaked— handshake state, set byPerformServerUpgrade/PerformClientUpgrade(internal→public)WebSocket.WsSendLock— lock that guardsPrepareSendFrame+ reading the send buffer (internal→public)WebSocket.WsSendBuffer— the framed output produced byPrepareSendFrame(internal→public)WebSocket Performance & Reliability Improvements:
WebSocket.MaskBufferfor fast payload processing.buffer.CopyTo).PrepareReceiveFrameheader parsing, replacing byte-by-byte loops.Sec-WebSocket-Accepthandshake validation using direct base64 comparison against computed SHA1 digest.WsGuidconstant.Buffer & HTTP Parsing Optimizations:
Buffer.Reservewith a 256-byte minimum allocation floor to reduce reallocation churn on small messages.Buffer.Append.BodyBytescopy inHttpRequestandHttpResponse.Test plan
WsSession/WssSession/WsClient/WssClientcall sites are unchanged.