abhinavsingh / proxy.py

💫 Ngrok FRP Alternative • ⚡ Fast • 🪶 Lightweight • 0️⃣ Dependency • 🔌 Pluggable • 😈 TLS interception • 🔒 DNS-over-HTTPS • 🔥 Poor Man's VPN • ⏪ Reverse & ⏩ Forward • 👮🏿 "Proxy Server" framework • 🌐 "Web Server" framework • ➵ ➶ ➷ ➠ "PubSub" framework • 👷 "Work" acceptor & executor framework
https://abhinavsingh.com/proxy-py-a-lightweight-single-file-http-proxy-server-in-python/
BSD 3-Clause "New" or "Revised" License
2.92k stars 569 forks source link

Unable to modify headers in a plugin #1273

Closed dmitriyvolk closed 1 year ago

dmitriyvolk commented 1 year ago

Check FAQs

Describe the bug Wrote a simple plugin to add headers to the proxied request. Plugin is loaded, executed, but has no effect

class MyPlugin(HttpProxyBasePlugin):
    def handle_client_request(self, request: HttpParser) -> Optional[HttpParser]:
        print(self.flags.disable_headers)
        print(request.headers)
        request.add_header(b"X-My-Test", b"Test Value")
        print(request.headers)
        return request

Request:

curl -x localhost:8899 -H 'Curl-Header: Curl Value' https://httpbin.org/anything

Log

[]
{b'host': (b'Host', b'httpbin.org:443'), b'user-agent': (b'User-Agent', b'curl/7.79.1'), b'proxy-connection': (b'Proxy-Connection', b'Keep-Alive')}
<proxy.http.parser.parser.HttpParser object at 0x1124b8dc0>
{b'host': (b'Host', b'httpbin.org:443'), b'user-agent': (b'User-Agent', b'curl/7.79.1'), b'proxy-connection': (b'Proxy-Connection', b'Keep-Alive'), b'x-my-test': (b'X-My-Test', b'Test Value')}

HTTP Bin response:

curl -x localhost:8899 -H 'Curl-Header: Curl Value' https://httpbin.org/anything
{
  "args": {},
  "data": "",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "*/*",
    "Curl-Header": "Curl Value",
    "Host": "httpbin.org",
    "User-Agent": "curl/7.79.1",
    "X-Amzn-Trace-Id": "Root=1-633612ae-0c9a14b22227c2b5204e2991"
  },
  "json": null,
  "method": "GET",
  "origin": "4.4.191.194",
  "url": "https://httpbin.org/anything"
}

Expected behavior

  1. I expect Curl-Header header to be passed to the plugin
  2. I expect X-My-Test header to be seen by HTTP Bin

Version information

Additional context Started proxy.py as:

 with proxy.Proxy(plugins=[MyPlugin]) as p:
            print(p.flags.port)
            proxy.sleep_loop()

Screenshots N/A

dmitriyvolk commented 1 year ago

Not an issue. I'm making an HTTPS request, of course the proxy can't see the headers.