Created
September 25, 2025 04:54
-
-
Save minrk/c833ba963e5898896602d9b53a5e31c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| services: | |
| proxy: | |
| image: ghcr.io/minrk/configurable-http-proxy:custom-dump-netstat | |
| # build: | |
| # context: .. | |
| command: | |
| - --error-target=http://error-target | |
| - --default-target=http://169.254.0.0 | |
| - --log-level=debug | |
| environment: | |
| DEBUG: "*" | |
| NETSTAT_SECONDS: "10" | |
| ports: | |
| - 8000:8000 | |
| error-target: | |
| build: | |
| context: error-target | |
This file contains hidden or 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
| FROM python:3.13-alpine | |
| RUN apk add --no-cache net-tools | |
| RUN pip install tornado | |
| COPY main.py /main.py | |
| CMD ["python3", "main.py"] |
This file contains hidden or 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
| import asyncio | |
| import tornado | |
| class MainHandler(tornado.web.RequestHandler): | |
| def get(self, code): | |
| self.write(f"Code: {code}") | |
| async def main(): | |
| application = tornado.web.Application([(r"/(.+)", MainHandler)]) | |
| http_server = tornado.httpserver.HTTPServer(application) | |
| http_server.listen(80) | |
| await asyncio.Event().wait() | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |
This file contains hidden or 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
| <html> | |
| <title>Websocket test</title> | |
| <body> | |
| <input type="checkbox" checked name="pause" id="pause"> | |
| <label for="pause">Pause</label> | |
| <input type="checkbox" checked name="websocket" id="websocket"> | |
| <label for="websocket">WebSocket</label> | |
| <ul id="output"></ul> | |
| <script type="text/javascript"> | |
| // document.location.href; | |
| const htmlUrl = "http://127.0.1:8000/"; | |
| const wsUrl = "ws" + htmlUrl.slice(4); | |
| const connectEveryMs = 100; | |
| function log(msg) { | |
| const ul = document.getElementById("output"); | |
| const li = document.createElement("li"); | |
| li.innerText = `${(new Date()).toLocaleTimeString()} ${msg}`; | |
| ul.insertBefore(li, ul.firstChild); | |
| // limit length | |
| if (ul.childElementCount > 10) { | |
| ul.removeChild(ul.lastChild); | |
| } | |
| } | |
| function connect() { | |
| if (document.getElementById("pause").checked) { | |
| setTimeout(connect, connectEveryMs); | |
| return; | |
| } | |
| if (document.getElementById("websocket").checked) { | |
| connectWs(); | |
| } else { | |
| connectFetch(); | |
| } | |
| }; | |
| async function connectFetch() { | |
| log(`fetching ${htmlUrl}`) | |
| try { | |
| const r = await fetch(htmlUrl); | |
| log("fetched ok"); | |
| } catch (e) { | |
| log(`fetch error ${e.toString()}`); | |
| console.error(e); | |
| } | |
| setTimeout(connect, connectEveryMs); | |
| } | |
| function connectWs() { | |
| log("connecting websocket"); | |
| const ws = new WebSocket(wsUrl); | |
| // connect every this often | |
| // these are all going to fail, | |
| // but it appears that failed ws connections are causing port exhaustion errors | |
| ws.onerror = (err) => { | |
| log("error"); | |
| console.error(err); | |
| }; | |
| ws.onclose = () => { | |
| log("close"); | |
| setTimeout(connect, connectEveryMs); | |
| } | |
| } | |
| connect(); | |
| </script> | |
| </body> | |
| </html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment