fix(proxy): ignore Referer if got redirect (close #3996)

This commit is contained in:
Andy Hsu
2023-03-31 20:29:55 +08:00
parent 0c5820a98f
commit 3b07c72f88
2 changed files with 12 additions and 29 deletions

View File

@ -343,9 +343,9 @@ func (c *Client) Read(path string) ([]byte, error) {
}
func (c *Client) Link(path string) (string, http.Header, error) {
method := "HEAD"
url := PathEscape(Join(c.root, path))
r, err := http.NewRequest(method, url, nil)
method := "GET"
u := PathEscape(Join(c.root, path))
r, err := http.NewRequest(method, u, nil)
if err != nil {
return "", nil, newPathErrorErr("Link", path, err)
@ -366,31 +366,6 @@ func (c *Client) Link(path string) (string, http.Header, error) {
if c.interceptor != nil {
c.interceptor(method, r)
}
rs, err := c.c.Do(r)
if err != nil {
return "", nil, newPathErrorErr("Link", path, err)
}
if rs.StatusCode == 401 {
wwwAuthenticateHeader := strings.ToLower(rs.Header.Get("Www-Authenticate"))
if strings.Contains(wwwAuthenticateHeader, "digest") {
c.authMutex.Lock()
c.auth = &DigestAuth{auth.User(), auth.Pass(), digestParts(rs)}
c.auth.Authorize(r, method, path)
c.authMutex.Unlock()
} else if strings.Contains(wwwAuthenticateHeader, "basic") {
c.authMutex.Lock()
c.auth = &BasicAuth{auth.User(), auth.Pass()}
c.auth.Authorize(r, method, path)
c.authMutex.Unlock()
} else {
return "", nil, newPathError("Authorize", c.root, rs.StatusCode)
}
} else if rs.StatusCode > 400 {
return "", nil, newPathError("Authorize", path, rs.StatusCode)
}
return r.URL.String(), r.Header, nil
}