Skip to content

Commit

Permalink
Merge pull request #1164 from shugen002/patch-1
Browse files Browse the repository at this point in the history
Add Note for WebSocket subprotocols
  • Loading branch information
ReneWerner87 authored Aug 26, 2024
2 parents c62abb2 + a8b65e7 commit 18e5577
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion websocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,12 @@ cfg := Config{
app.Get("/ws/:id", websocket.New(func(c *websocket.Conn) {}, cfg))


```
```
## Note for WebSocket subprotocols
The config `Subprotocols` only helps you negotiate subprotocols and sets a `Sec-Websocket-Protocol` header if it has a suitable subprotocol. For more about negotiates process, check the comment for `Subprotocols` in [fasthttp.Upgrader](https://pkg.go.dev/github.com/fasthttp/websocket#Upgrader) .
All connections will be sent to the handler function no matter whether the subprotocol negotiation is successful or not. You can get the selected subprotocol from `conn.Subprotocol()`.
If a connection includes the `Sec-Websocket-Protocol` header in the request but the protocol negotiation fails, the browser will immediately disconnect the connection after receiving the upgrade response.

0 comments on commit 18e5577

Please sign in to comment.