Skip to content

Commit

Permalink
Close connection if authentication failed
Browse files Browse the repository at this point in the history
libcurl and some proxy application will keep sending authentication in
same connection if auth failed which is not supported.

fixes #583
  • Loading branch information
mengzhuo authored and ginuerzh committed Nov 18, 2020
1 parent fd079dd commit 1c32df3
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,12 @@ func (h *httpHandler) authenticate(conn net.Conn, req *http.Request, resp *http.
conn.RemoteAddr(), conn.LocalAddr())
resp.StatusCode = http.StatusProxyAuthRequired
resp.Header.Add("Proxy-Authenticate", "Basic realm=\"gost\"")
if strings.ToLower(req.Header.Get("Proxy-Connection")) == "keep-alive" {
// XXX libcurl will keep sending auth request in same conn
// which we don't supported yet.
resp.Header.Add("Connection", "close")
resp.Header.Add("Proxy-Connection", "close")
}
} else {
resp.Header = http.Header{}
resp.Header.Set("Server", "nginx/1.14.1")
Expand Down

0 comments on commit 1c32df3

Please sign in to comment.