<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>mitmproxy on foosel.net</title><link>https://foosel.net/tags/mitmproxy/</link><description>Recent content in mitmproxy on foosel.net</description><generator>Hugo</generator><language>en-us</language><copyright>Gina Häußge (foosel)</copyright><lastBuildDate>Tue, 12 Mar 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://foosel.net/tags/mitmproxy/feed.xml" rel="self" type="application/rss+xml"/><item><title>How to quickly create a header modifying reverse proxy with mitmproxy</title><link>https://foosel.net/til/how-to-quickly-create-a-header-modifying-reverse-proxy-with-mitmproxy/</link><pubDate>Tue, 12 Mar 2024 00:00:00 +0000</pubDate><guid>https://foosel.net/til/how-to-quickly-create-a-header-modifying-reverse-proxy-with-mitmproxy/</guid><description>&lt;p&gt;I&amp;rsquo;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.&lt;/p&gt;
&lt;p&gt;Specifically, I wanted a quick CLI tool that would allow me to set up a reverse proxy listening on port 5555, forwarding to
&lt;code&gt;http://localhost:5000&lt;/code&gt; while also setting the headers &lt;code&gt;X-Remote-User&lt;/code&gt; to &lt;code&gt;remote&lt;/code&gt; and &lt;code&gt;X-Remote-Host&lt;/code&gt; to &lt;code&gt;localhost:5555&lt;/code&gt;.&lt;/p&gt;</description><content:encoded><![CDATA[<p>I&rsquo;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.</p>
<p>Specifically, I wanted a quick CLI tool that would allow me to set up a reverse proxy listening on port 5555, forwarding to
<code>http://localhost:5000</code> while also setting the headers <code>X-Remote-User</code> to <code>remote</code> and <code>X-Remote-Host</code> to <code>localhost:5555</code>.</p>
<p>Enter <a href="https://mitmproxy.org/"><code>mitmproxy</code></a>, or more specifically its <code>mitmdump</code> tool, which turned out to be a great tool for this job.</p>
<p>All I needed was to run the following command:</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>mitmdump --mode reverse:http://localhost:5000@5555 --modify-headers <span style="color:#e6db74">&#34;/X-Remote-User/remote&#34;</span> --modify-headers <span style="color:#e6db74">&#34;/X-Forwarded-Host/localhost:5555&#34;</span>
</span></span></code></pre></div><p>This does the following:</p>
<ul>
<li><code>--mode reverse:http://localhost:5000@5555</code> sets up a reverse proxy listening on port 5555, forwarding to <code>http://localhost:5000</code></li>
<li><code>--modify-headers &quot;/X-Remote-User/remote&quot;</code> sets the <code>X-Remote-User</code> header to <code>remote</code></li>
<li><code>--modify-headers &quot;/X-Forwarded-Host/localhost:5555&quot;</code> sets the <code>X-Forwarded-Host</code> header to <code>localhost:5555</code></li>
</ul>
<p>With that the <a href="https://community.octoprint.org/t/reverse-proxy-configuration-examples/1107">reverse proxy test page in OctoPrint</a>
turned all green and I could test my changes without having to set up an actual reverse proxy in front of the development server.</p>
]]></content:encoded></item></channel></rss>