Update README.md

This commit is contained in:
Jarred Sumner
2022-10-17 04:36:22 -07:00
parent 9a2f2a94bf
commit ca02695993

View File

@@ -2265,9 +2265,17 @@ For server websocket connections, Bun exposes a `ServerWebSocket` class which is
`ServerWebSocket` supports passing headers. This is useful for setting cookies or other headers that you want to send to the client before the connection is upgraded.
```ts
server.upgrade(req, {
headers: {
"Set-Cookie": "name=" + new URL(req.url).searchParams.get("name"),
Bun.serve({
fetch(req, server) {
if (
server.upgrade(req, { headers: { "Set-Cookie": "name=HiThereMyNameIs" } })
)
return;
},
websocket: {
message(ws, message) {
ws.send(message);
},
},
});
```