Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not appear to work at all #426

Open
mcfearsome opened this issue Feb 20, 2021 · 3 comments
Open

Does not appear to work at all #426

mcfearsome opened this issue Feb 20, 2021 · 3 comments

Comments

@mcfearsome
Copy link

mcfearsome commented Feb 20, 2021

The following code snippet does not produce any output, proxy behavior is working just fine, DoFunc just never gets called.

❯ go version
go version go1.16beta1 darwin/arm64
# p.server is created with goproxy.NewProxyHttpServer()
p.server.OnResponse().DoFunc(func(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
	log.Println("OnResponse")
	log.Println(resp.Request.Host)
	log.Printf("%+v\n", resp.Request)
	os.Exit(1)
	return resp
})

The following produces some output, but the proxy behavior breaks, as in I can't browse anymore:

	var handler goproxy.FuncHttpsHandler = func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) {
		log.Println("HandleConnect")
		log.Printf("Host: %s\n", host)

		return goproxy.OkConnect, ""
	}
	p.server.OnRequest().HandleConnect(handler)
@iIIusi0n
Copy link

iIIusi0n commented Feb 28, 2021

It doesn't support Https MITM 👍

@CoolSpring8
Copy link
Contributor

CoolSpring8 commented Feb 28, 2021

By default only http traffic is handled by these OnRequest/OnResponse handlers, while https traffic will pass through untouched.
Depending on what you like to do on https connections, you might want something like AlwaysMitm or AlwaysReject.

So to explain why the snippets doesn't work:

  • In the first snippet, the proxy server is not yet configured to act on a https connection (as described above). Therefore, when visiting a site with https, the handler function is never called; If you visit a site without https, the information is expected to be logged.

  • In the second snippet, the var handler goproxy.FuncHttpsHandler you defined returns an empty string as the host, which is invalid for a CONNECT request, and that prevents the normal browsing.

(There are some examples available for reference in the examples directory and I would suggest checking out some of them.)

@JanneKiiskila
Copy link

Should this issue closed, if the answer suffices @mcfearsome ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants