elazarl / goproxy

An HTTP proxy library for Go
BSD 3-Clause "New" or "Revised" License
5.98k stars 1.09k forks source link

Does not appear to work at all #426

Open mcfearsome opened 3 years ago

mcfearsome commented 3 years ago

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 commented 3 years ago

It doesn't support Https MITM 👍

CoolSpring8 commented 3 years ago

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:

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

JanneKiiskila commented 1 year ago

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