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

HTTP in cascadeproxy example returns Proxy Authentication Required #306

Closed
gbraad opened this issue Aug 10, 2018 · 5 comments · Fixed by #391
Closed

HTTP in cascadeproxy example returns Proxy Authentication Required #306

gbraad opened this issue Aug 10, 2018 · 5 comments · Fixed by #391

Comments

@gbraad
Copy link

gbraad commented Aug 10, 2018

When setting

request, err := http.NewRequest("GET", "https://ip.cn", nil)

as

-	request, err := http.NewRequest("GET", "https://ip.cn", nil)
+	request, err := http.NewRequest("GET", "http://ip.cn", nil)

execution results in

$ ./main
2018/08/10 05:37:35 serving end proxy server at localhost:8082
2018/08/10 05:37:35 serving middle proxy server at localhost:8081
2018/08/10 05:37:36 [001] INFO: Got request / ip.cn GET http://ip.cn/
2018/08/10 05:37:36 [001] INFO: Sending request GET http://ip.cn/
2018/08/10 05:37:36 [001] INFO: Got request / ip.cn GET http://ip.cn/
2018/08/10 05:37:36 [001] INFO: Copying response to client  [407]
2018/08/10 05:37:36 [001] INFO: Copied 33 bytes to client error=<nil>
2018/08/10 05:37:36 [001] INFO: Received response 407 Proxy Authentication Required
2018/08/10 05:37:36 [001] INFO: Copying response to client 407 Proxy Authentication Required [407]
2018/08/10 05:37:36 [001] INFO: Copied 33 bytes to client error=<nil>
2018/08/10 05:37:36 status 407, data 407 Proxy Authentication Required

While the headers are set in middleproxy using:

middleProxy.OnRequest().Do(goproxy.FuncReqHandler(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
SetBasicAuth(username, password, req)
return req, nil
}))

func SetBasicAuth(username, password string, req *http.Request) {
req.Header.Set(ProxyAuthHeader, fmt.Sprintf("Basic %s", basicAuth(username, password)))
}

they do not seem to arrive at the endproxy.

@gbraad
Copy link
Author

gbraad commented Aug 10, 2018

@liudanking WDYT?

@liudanking
Copy link
Contributor

liudanking commented Aug 11, 2018 via email

@liudanking
Copy link
Contributor

Hi @gbraad, the reason is that the middle proxy removes the auth header:

https://github.com/elazarl/goproxy/blob/master/proxy.go#L88

add @elazarl

@gbraad
Copy link
Author

gbraad commented Aug 11, 2018

This should be configurable, as it is not always wanted to remove headers... especially in this case it should be passed on.

Note: this was changed as part of #78


As of Proxy-* headers, seems like a good idea to remove those, will do in a few days.

Maybe not... :-s Can this be made configurable... ?

@azak-azkaran
Copy link

This is still not fixed and could be fixed with @gbraad proposed changes.

azak-azkaran pushed a commit to azak-azkaran/goproxy that referenced this issue Jun 19, 2020
This was referenced Jun 19, 2020
elazarl pushed a commit that referenced this issue Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants