elazarl / goproxy

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

Core Functionality Broken #533

Open nik-ngp opened 7 months ago

nik-ngp commented 7 months ago

I basically copy and pasted the example of http-dump, however, nothing is being written to log. It's just empty. I also tried using .OnRequest().DoFunc() however it's not working as well.

The following code would never panic for some strange reason.

It would however proxy the traffic normally and print in the console: $ HOST=127.0.0.1 PORT=8081 go run . 2024/04/11 11:57:40 [001] INFO: Running 0 CONNECT handlers 2024/04/11 11:57:40 [002] INFO: Running 0 CONNECT handlers 2024/04/11 11:57:40 [003] INFO: Running 0 CONNECT handlers 2024/04/11 11:57:40 [001] INFO: Accepting CONNECT to www.google.com:443

` package main

import ( "api/env" "fmt" "net" "net/http" "os"

"github.com/elazarl/goproxy"

)

func main() { proxy := goproxy.NewProxyHttpServer() proxy.Verbose = true

proxy.OnRequest().DoFunc(
    func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
        panic("not called")
        return r, nil
    })

if err := http.ListenAndServe(net.JoinHostPort(env.SRV_ADDR, env.SRV_PORT), proxy); err != nil {
    fmt.Println(err)
    os.Exit(1)
}

} `

Edit: Some random POST requests would go trough an call the hook. Log: 2024/04/11 12:00:31 [020] INFO: Got request / ocsp.sectigo.com POST http://ocsp.sectigo.com/

nik-ngp commented 7 months ago

I also tried Reddit blocking example, doesn't work. Go version 1.22.2

nik-ngp commented 7 months ago

Replicated the issue in a Linux VM.

nik-ngp commented 7 months ago

It does work, however, I'd need to set trusted root cert if I wish to intercept HTTPS traffic.

elazarl commented 7 months ago

Correct, maybe I should add setting root cert to the example.

On Fri, Apr 12, 2024, 15:06 nik-ngp @.***> wrote:

It does work, however, I'd need to set trusted root cert if I wish to intercept HTTPS traffic.

— Reply to this email directly, view it on GitHub https://github.com/elazarl/goproxy/issues/533#issuecomment-2051632667, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAB7RIRKLPFHZDJHQD3SIW3Y47E4LAVCNFSM6AAAAABGB7SNGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJRGYZTENRWG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

nik-ngp commented 7 months ago

That would be quite real helpful to have an example with the cert. Maybe even, if not too much to ask, an option to generate keys, serialize them into a certificate so that the whole system can trust it.

I will kindly re-open the ticket with this comment. If you're willing to proceed with the additional example we can attach a PR to this issue.

zarkones commented 2 months ago

Hello @elazarl . I think such an example for root cert would be really useful. Do you have maybe a timeline of when you could do it for us? :)