-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
til: mitmproxy/-dump as reverse proxy
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
...nt/til/how-to-quickly-create-a-header-modifying-reverse-proxy-with-mitmproxy.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: "How to quickly create a header modifying reverse proxy with mitmproxy" | ||
date: 2024-03-12 | ||
tags: | ||
- mitmproxy | ||
- command line | ||
- octoprint | ||
--- | ||
|
||
I'm currently in the process of testing some changes on OctoPrint involving its automatic user login via request headers, and | ||
for that needed to quickly set up a reverse proxy that would modify the headers of the requests going to the development server | ||
for some quick testing. | ||
|
||
Specifically, I wanted a quick CLI tool that would allow me to set up a reverse proxy listening on port 5000, forwarding to | ||
`http://localhost:5000` while also setting the headers `X-Remote-User` to `remote` and `X-Remote-Host` to `localhost:5555`. | ||
|
||
Enter [`mitmproxy`](https://mitmproxy.org/), or more specifically its `mitmdump` tool, which turned out to be a great tool for this job. | ||
|
||
All I needed was to run the following command: | ||
|
||
```bash | ||
mitmdump --mode reverse:http://localhost:5000@5555 --modify-headers "/X-Remote-User/remote" --modify-headers "/X-Forwarded-Host/localhost:5555" | ||
``` | ||
|
||
This does the following: | ||
|
||
- `--mode reverse:http://localhost:5000@5555` sets up a reverse proxy listening on port 5555, forwarding to `http://localhost:5000` | ||
- `--modify-headers "/X-Remote-User/remote"` sets the `X-Remote-User` header to `remote` | ||
- `--modify-headers "/X-Forwarded-Host/localhost:5555"` sets the `X-Forwarded-Host` header to `localhost:5555` | ||
|
||
With that the [reverse proxy test page in OctoPrint](https://community.octoprint.org/t/reverse-proxy-configuration-examples/1107) | ||
turned all green and I could test my changes without having to set up an actual reverse proxy in front of the development server. |