From cf0fc6e4a02a352e36f7c909a6e2440b2933e6ee Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Sat, 2 Dec 2017 17:07:42 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=AE=8C=E5=96=84HTTP=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E8=AE=A4=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/http/server.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/proxy/http/server.go b/proxy/http/server.go index e1f371b67..57f86c344 100644 --- a/proxy/http/server.go +++ b/proxy/http/server.go @@ -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 } } From 8ec1a98040b17ce50f45ea48b09bfae124689ff1 Mon Sep 17 00:00:00 2001 From: sunshineplan Date: Sun, 3 Dec 2017 10:45:26 +0800 Subject: [PATCH 2/2] update http connect test --- testing/scenarios/http_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/scenarios/http_test.go b/testing/scenarios/http_test.go index d0033deff..0e4752aef 100644 --- a/testing/scenarios/http_test.go +++ b/testing/scenarios/http_test.go @@ -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) } {