---
title: WebSocket
description: Bidirectional tunneling and upgrades.
icon: Replace
---
import { Step, Steps } from 'fumadocs-ui/components/steps';
## Logic Flow
WebSockets require a "Protocol Upgrade" within L7. Vane handles this via a multi-phase process.
<Steps>
<Step>
### Ingress & Capture
The Adapter detects the upgrade request and "steals" the upgrade handle from Hyper before the request body is processed.
<Mermaid
chart="
graph LR
Client[Client] -->|GET /ws| Hyper
Hyper -->|Parse| Adapter
Adapter -->|Extract Future| Handle[Client Upgrade Handle]
Handle -->|Store| Container[Container ProtocolData]
Adapter -->|Request| Flow[Flow Engine]
"
/>
</Step>
<Step>
### Upstream Negotiation
The `FetchUpstream` middleware connects to the backend. If the backend accepts the upgrade (HTTP 101), Vane captures the _upstream_ upgrade handle.
<Mermaid
chart="
graph LR
Flow -->|Execute| Upstream[Fetch Upstream]
Upstream -->|GET /ws| Backend
Backend -->|HTTP 101| Upstream
Upstream -->|Extract Future| Handle[Upstream Upgrade Handle]
Handle -->|Store| Container
"
/>
</Step>
<Step>
### Tunnel Establishment
The `SendResponse` terminator detects both handles. It sends the final 101 response to the client (triggering the switch) and spawns a background tunnel.
<Mermaid
chart="
graph LR
Terminator -->|Check Handles| Container
Terminator -->|Send HTTP 101| Client
Terminator -->|Spawn| Tunnel[Tunnel Task]
ClientIO[Client Socket] <-->|Bi-Directional Copy| Tunnel
UpstreamIO[Backend Socket] <-->|Bi-Directional Copy| Tunnel
"
/>
</Step>
</Steps>