Skip to content

Commit 9b72812

Browse files
committed
doc: how to bypass Bad Gateway when mitmproxy is acting as a proxy
1 parent a819870 commit 9b72812

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,27 @@ mitmweb --ssl-insecure --set stream_large_bodies="10m" --mode socks5
220220
>
221221
in: https://youtrack.jetbrains.com/issue/TBX-14532/Missing-proxy-authentication-settings#focus=Comments-27-12265861.0-0
222222

223+
### Mitmproxy returns 502 Bad Gateway to the client
224+
225+
When running traffic through mitmproxy, you may encounter 502 Bad Gateway errors that mention HTTP/2 protocol error: *
226+
*Received header value surrounded by whitespace**.
227+
This happens because some upstream servers (including dev.coder.com) send back headers such as Content-Security-Policy
228+
with leading or trailing spaces.
229+
While browsers and many HTTP clients accept these headers, mitmproxy enforces the stricter HTTP/2 and HTTP/1.1 RFCs,
230+
which forbid whitespace around header values.
231+
As a result, mitmproxy rejects the response and surfaces a 502 to the client.
232+
233+
The workaround is to disable HTTP/2 in mitmproxy and force HTTP/1.1 on both the client and upstream sides. This avoids
234+
the strict header validation path and allows
235+
mitmproxy to pass responses through unchanged. You can do this by starting mitmproxy with:
236+
237+
```bash
238+
mitmproxy --set http2=false --set upstream_http_version=HTTP/1.1
239+
```
240+
241+
This ensures coder toolbox http client ↔ mitmproxy ↔ server connections all run over HTTP/1.1, preventing the whitespace
242+
error.
243+
223244
## Debugging and Reporting issues
224245

225246
Enabling debug logging is essential for diagnosing issues with the Toolbox plugin, especially when SSH

0 commit comments

Comments
 (0)