Commit 5fc6504
fix(janus-proxy): tunnel raw bytes to preserve WS upgrade headers
The previous proxy used http.ReadResponse + resp.Write to forward Janus's
101 Switching Protocols response back to the browser. Both steps mangled
the upgrade:
- ReadResponse normalizes header casing via MIME canonicalization, so
Janus's "Sec-Websocket-Accept" / "Upgrade: WebSocket" headers came out
rewritten and the browser closed the connection.
- resp.Write treats a 101 response's Body as the rest of the upgraded
stream and tries to copy it into the client conn before we ever get
to the bidirectional bridge — blocking client→server frames.
Read the response status + headers as raw bytes until \r\n\r\n, verify
HTTP/1.1 101, write the bytes verbatim to the client, then start the
two-way io.Copy. Browser-side WebSocket now establishes cleanly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 1d18d74 commit 5fc6504
1 file changed
Lines changed: 28 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
68 | | - | |
| 69 | + | |
| 70 | + | |
69 | 71 | | |
70 | 72 | | |
71 | | - | |
| 73 | + | |
72 | 74 | | |
73 | 75 | | |
74 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
75 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
76 | 85 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
80 | 100 | | |
81 | 101 | | |
82 | 102 | | |
| |||
91 | 111 | | |
92 | 112 | | |
93 | 113 | | |
94 | | - | |
95 | | - | |
| 114 | + | |
| 115 | + | |
96 | 116 | | |
97 | 117 | | |
98 | 118 | | |
| |||
0 commit comments