elazarl / goproxy

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

goproxy not working when set as https_proxy #479

Open k-p-ani opened 2 years ago

k-p-ani commented 2 years ago

Hi, When i start goproxy instance at 8080 and then try to connect a target secured site with https scheme, I observed that proxy.OnRequest().DoFunc is never called. Below is how I call the secured target site after setting https_proxy variable, this variable points to my goproxy instance running at port 8080.

https_proxy=http://0.0.0.0:8080 wget https://webhook.site/f227e786-e662-429c-8e69-dc8c57e2249e --header="Content-Type: text/json" --post-file=/home/ubuntu/go/src/warden-proxy/mydata.json


Out put of above wget execution is as below

--2022-07-06 10:17:47-- https://webhook.site/f227e786-e662-429c-8e69-dc8c57e2249e Connecting to 0.0.0.0:8080... connected. Proxy request sent, awaiting response... 200 OK Length: unspecified [text/plain] Saving to: ‘f227e786-e662-429c-8e69-dc8c57e2249e’



goproxy console output as below

2022/07/06 10:17:47 [001] INFO: Running 1 CONNECT handlers 2022/07/06 10:17:47 [001] INFO: Accepting CONNECT to webhook.site:443



DoFunc implementation

`proxy.OnRequest().DoFunc(

            func(r *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
        log.Println("on request called")
        r.Header.Set("X-GoProxy", "yxorPoG-X")
        return r, nil
    })
    `

Thanks in advance.

faf-xff commented 1 year ago

你解决了吗

faf-xff commented 1 year ago

可能是因为少写了
proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm)