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 代理可能存在问题 #39

Closed
Mythologyli opened this issue Sep 27, 2023 · 2 comments
Closed

HTTP 代理可能存在问题 #39

Mythologyli opened this issue Sep 27, 2023 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed question Further information is requested

Comments

@Mythologyli
Copy link
Owner

Mythologyli commented Sep 27, 2023

https://www.cc98.org/topic/5708120

当使用 zju-connect 内置的 http 代理时,进行统一身份认证时可能出现界面加载问题:
image

使用学在浙大测试发现,该现象不是每次都出现,反复登录-注销有几率触发。有时表现为界面加载不全,有时表现为无限重定向;使用 Clash + 内置 SOCKS5 代理,不会出现此现象

目前原因未知,怀疑 http 代理的实现可能存在问题

@Mythologyli Mythologyli added bug Something isn't working help wanted Extra attention is needed question Further information is requested labels Sep 27, 2023
@cxz66666
Copy link
Collaborator

之前用zju connect的http proxy测试 appservice.zju.edu.cn 的时候也触发过,刷新几次好像就行了,后面可以多测试下

@Mythologyli
Copy link
Owner Author

已修复

问题分析

req.RequestURI = ""

resp, err := client.Do(req)
if err != nil {
	w.WriteHeader(500)
	w.Write([]byte(err.Error() + "\n"))
	return
}

hdr := w.Header()
for k, v := range resp.Header {
	hdr[k] = v
}

w.WriteHeader(resp.StatusCode)

io.Copy(w, resp.Body)

此处 http client 默认的行为是自动处理重定向,所以 302 根本不会返回到浏览器

而统一认证登录中对整个路径都进行了 302,这导致请求 js 也会返回重定向后的 html 内容:
bdf884ba1de383bf150cb681cee0aba7

解决方法

func newClient() *http.Client {
	return &http.Client{
		Transport: &http.Transport{
			Dial: func(net, addr string) (net.Conn, error) {
				return socks5proxy.Dial(net, addr)
			},
		},
		CheckRedirect: func(req *http.Request, via []*http.Request) error {
			return http.ErrUseLastResponse
		},
	}
}

直接将重定向交给浏览器

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants