Assume that on the same host, I have the process X which is a Golang HTTP Server listening on any port. At the same time, I have also another Golang process Y that could be a CLI tool, an HTTP server, a GUI tool,… My wish is that every time there is an HTTP request is sent to process X, process Y somehow immediately read the information of this request (headers, URL, body,…) and print them to console.
Is there any solution to achieve the above without changing the source code of process X (Golang HTTP Server)? One solution I can think of is to use NGINX as a proxy that can fork an HTTP request to both X and Y. But what I want is for process Y to do it on its own.
There is a special tool called Wireshark that is capable of capturing all ingress and egress traffic for any interface/ip/port/etc. Knowing a port one could easily view all incoming traffic given the data is not encrypted. If you want your Y process to be able to do that you could do a research on how Wireshark does it. There has to be some API exposed by OS that would let you do that. You most likely would need some root privileges though.
Also, consider this repo https://github.com/sipt/shuttle
Answered By – Dmitrii Dunaev
Answer Checked By – Marie Seifert (GoLangFix Admin)