Repository navigation
Move websocket header normalization later - #7921
Conversation
|
Seems to me like #7786 should cover this already |
|
I think this placement is cleaner than 7786: it normalises once immediately before reverseProxy, after the request-header changes and only for upgrade requests. Please bring over a regression test which exercises this actual proxy-loop path and fails when the call is removed; with that coverage I would prefer this PR. |
A regression since caddyserver#6621, these headers can be rewritten by cloneHeaders and by .Add from user and transport ops. Moving this closer to where it's round-tripped feels like the nicest solution. I've put the harness I used to reproduce the issue at https://codeberg.org/nfreya/caddy-websocket-headers-repro
24f7ca9 to
34eb794
Compare
|
Took a bit to get back to this, sorry. There's now an integration test for the WebSocket header normalization which fails if the first commit of the branch is removed. This catches the #7784 |
steadytao
left a comment
There was a problem hiding this comment.
No need to be sorry. Thank you very much for your work. Just a issue in goroutine handling but otherwise very lovely!
34eb794 to
2cfa67e
Compare
2cfa67e to
b2756d9
Compare
b2756d9 to
dcde178
Compare
steadytao
left a comment
There was a problem hiding this comment.
Thank you very much, freya. LGTM.
|
Pending #7964 -- I hate CI :D |
A regression since #6621, these headers can be rewritten by
cloneRequestand byreq.Headers.Addfrom e.g. user and transport ops. Moving this closer to where it's round-tripped feels like the nicest solution.I've put the harness I used to reproduce the issue at
https://codeberg.org/nfreya/caddy-websocket-headers-repro
I encountered this issue while trying to reverse proxy the iKVM from an old SuperMicro BMC which was using some ancient noVNC fork, and I had a suspicion that the 400 response from the upstream was due to
CanonicalMIME-related normalization combined with the sort of naivestrstryou'd expect in the C code of a firmware written under ... 'constraints.' From there I found the comment referencing #6621 and the open #7784. Since that more recent one has AI usage, I didn't look further into it on principle, and from skimming the corresponding #7786 now, it looks uglier than my approach of just moving the normalize down. Any unintended consequences of this movement would be limited to consumers of the headers that branch on case difference for a request between the old and newnormalizeWebsocketHeaderscall site, and that seems like a rare enough edge case with obviously unsupported semantics to be worth breaking for simplicity's sake. If some unit tests of this behaviour are necessary for acceptance we can do that, but the regression itself was caused in a way that seems difficult to guard against by anything other than relatively fragile integration testing, so I've left it at this.git log -Sshowed me #7911 affecting something tangential since those allocations come from the same mismatch betweenCanonicalMIMEand the original websocket RFC -- this PR doesn't make that situation strictly worse, as leaving these headers inCanonicalMIMEform before the request is cloned however many timesreverse_proxyends up cloning it makes it less likely for that allocation to occur, but I also think thenormalizeWebsocketHeadersmethod is unlikely do any allocations since it's just migrating a (pointer-to-const key, slice value) from one hashmap slot to another (unverified). The extraupgradeTypecall is in the path of every request, but memoizing that seems annoying just to eliminate what is just a scan of the map when there's so much other code in this path.Assistance Disclosure
No AI was used.