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
3.01k stars 573 forks source link

Using embedded Proxy input_args breaks logging/stdout #1336

Open klmunday opened 1 year ago

klmunday commented 1 year ago

I am currently creating an application which embeds proxy.py with a custom plugin. Due to requiring custom flags within the custom plugin I am having to use the workaround detailed in https://github.com/abhinavsingh/proxy.py/issues/871 in order for them to parse correctly.

I have noticed that since implementing this workaround that I am no longer getting any logs/stdout from the proxy.

Simplified version of my code below.

def run_proxy() -> None:    
    proxy_py_args = [
        "--plugin", "<my plugin>",
        "--disable-headers", "Via"
    ]
    with proxy.Proxy(
            port=9000,
            input_args=proxy_py_args
    ) as p:
        logging.info(f"starting proxy at {p.flags.hostname}:{p.flags.port}")
        print(p.flags)
        proxy.sleep_loop()

I do not see the message from logging.info in stdout. However, I do see the print. I have tried specifying a log-file which seems to parse correctly into p.flags but it does not get written to.

However, when I run the following I see the regular logging/stdout.

def run_proxy() -> None:
    with proxy.Proxy(
            port=9000,
            plugins=["<plugin name>"]
    ) as _:
        proxy.sleep_loop()

This however breaks the parsing of the custom plugins flags (as detailed in https://github.com/abhinavsingh/proxy.py/issues/871) so this is not a solution.

I have also tried using proxy.main instead, then specifying my args via command line but that has not worked.

abhinavsingh commented 1 year ago

@klmunday Thanks for reporting, this needs little investigation. I don't think we have enough test coverage for custom plugin "flags", so this may have gone rogue. Give me some time, will look into it and #871