Unify the WebSocket and HTTP pipelines
Predecessor
Idea
Proposal — merge the WebSocket and HTTP pipelines
Status: planning only. This draft intentionally contains no implementation, tests, or documentation changes yet. It captures the goal and a proposed plan for discussion before any code is written. Opened per @raman-m's suggestion on #2406 to start the follow-up; no rush expected until the next release cycle.
Goal
Remove the forked WebSocket pipeline and route WebSocket upgrade requests through the same Ocelot pipeline as ordinary HTTP requests. This is the larger follow-up discussed on #2406 (the #2403 IP-security fix), where the fork was the root cause of the bypass.
Why
A WebSocket request is an ordinary HTTP request until AcceptWebSocketAsync. Today app.MapWhen(IsWebSocketRequest, ConfigureWebSockets) forks it into a hand-maintained subset of middlewares, which is why WS upgrades miss most Ocelot features (auth, authz, rate limiting, claims, header transforms) and why each gap has to be patched in the forked pipeline separately.
Proposed approach
- Drop the
MapWhenWS fork inOcelotPipelineExtensions.BuildOcelotPipeline. - Make
WebSocketsProxyMiddlewareself-checkIsWebSocketRequestand pass non-WS requests through, registering it as a normal pipeline stage afterDownstreamUrlCreatorMiddlewareso WS terminates there and HTTP continues to cache/requester. - Preserve user overrides (
WebSocketsMiddlewareType/WebSocketsMiddleware). - Decide the fate of the now-unused public
ConfigureWebSocketsextension (keep /[Obsolete]).
Open questions for maintainers
- Is this the shape you had in mind (one flat pipeline, checker in the proxy), or would you prefer a different structure?
- Are there concerns with making the public
ConfigureWebSockets'[Obsolete]'? - Expected behaviour changes to call out (e.g. custom
MapWhenOcelotPipelinebranches would begin to see WS upgrade traffic; browser WS clients can't send anAuthorizationheader). - Are there any features which should remain explicitly unsupported for WS upgrades?
Source: ThreeMammals/Ocelot