A Go application that demonstrates how to use go-mitmproxy
to intercept, modify, and display HTTP requests and responses.
- URL Rewriting: Redirects requests intended for
naver.com
to a local web backend running onlocalhost:51231
. - Local Web Backend: A simple HTTP server that listens on
localhost:51231
, prints the details of incoming requests, and sends a response with those details. - Proxy Server: Uses
go-mitmproxy
to start a proxy server on port:9080
.
- The
RewriteHost
struct implements theRequestheaders
method of thego-mitmproxy
Addon interface. This method checks if the incoming request's host isnaver.com
. If it is, the request's URL and scheme are modified to target the local web backend. - The
runWebBackend
function initializes an HTTP server onlocalhost:51231
. The server uses thehandleRequest
function to handle incoming requests. - The
printRequestDetails
function is used to print the details (headers and body) of the incoming request to the console. - The
writeResponseDetails
function sends a response to the requester with the request's details. - The
main
function sets up and starts the proxy server. The proxy server uses two addons:RewriteHost
(for URL rewriting) andproxy.LogAddon
(for logging).
To run the application:
- Ensure you have the
go-mitmproxy
package installed. - Run the main application:
go run main.go
- Configure your browser or HTTP client to use a proxy server with the address
localhost:9080
. - Make a request to
naver.com
. You should see the request details printed in the console, and the response will contain the same details.