1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

Merge pull request #758 from sunshineplan/master

完善HTTP基本认证
This commit is contained in:
DarienRaymond 2017-12-05 21:32:58 +01:00 committed by GitHub
commit 82009c869e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 8 deletions

View File

@ -118,14 +118,11 @@ Start:
return trace
}
if len(s.config.Accounts) > 0 {
if len(s.config.Accounts) > 0 {
user, pass, ok := parseBasicAuth(request.Header.Get("Proxy-Authorization"))
if !ok {
_, err := conn.Write([]byte("HTTP/1.1 407 Proxy Authentication Required\r\n\r\n"))
return err
}
if !s.config.HasAccount(user, pass) {
_, err := conn.Write([]byte("HTTP/1.1 401 UNAUTHORIZED\r\n\r\n"))
if !ok || !s.config.HasAccount(user, pass) {
_, err := conn.Write([]byte("HTTP/1.1 407 Proxy Authentication Required\r\n" +
"Proxy-Authenticate: Basic realm=\"V2Ray\"\r\n\r\n"))
return err
}
}

View File

@ -284,7 +284,7 @@ func TestHttpBasicAuth(t *testing.T) {
setProxyBasicAuth(req, "a", "c")
resp, err := client.Do(req)
assert(err, IsNil)
assert(resp.StatusCode, Equals, 401)
assert(resp.StatusCode, Equals, 407)
}
{