-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Problem Description
I'm trying to debug a HTTP application on a server and need mitmproxy to listen on a HTTPS port. I need features from Nginx so I made nginx proxy_pass to a Unix socket. I don't want to make mitmproxy accessible outside of Nginx.
Proposal
The ability to listen on a unix socket in server modes should be added.
I addition, a feature to get the real IP from X-Real-IP or X-Forwarded-For would be needed!
This is needed for reverse-proxying mitmproxy's reverse proxy without Unix sockets in between too.
The architecture for ProxyMode would need to be changed slightly to accept anything not fitting with to a host string and a port number:
mitmproxy/mitmproxy/proxy/mode_specs.py
Lines 56 to 59 in 0ff08f9
| custom_listen_host: str | None | |
| """A custom listen host, if specified in the spec.""" | |
| custom_listen_port: int | None | |
| """A custom listen port, if specified in the spec.""" |
AsyncioServerInstance._start and .listen would also need to be changed to be able to listen on a Unix socket:
mitmproxy/mitmproxy/proxy/mode_servers.py
Lines 271 to 275 in 0ff08f9
| async def listen( | |
| self, host: str, port: int | |
| ) -> list[asyncio.Server | mitmproxy_rs.UdpServer]: | |
| if self.mode.transport_protocol not in ("tcp", "udp", "both"): | |
| raise AssertionError(self.mode.transport_protocol) |
Alternatives
I could use socat, but it's error-prone and I still would need the feature to get the real IP.
Additional context
import socket
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind("/tmp/socket_test.sock")