Commit cfd12235 authored by rui.zheng's avatar rui.zheng

minor fix

parent 821ab4d3
...@@ -109,6 +109,9 @@ func (h *httpHandler) Handle(conn net.Conn) { ...@@ -109,6 +109,9 @@ func (h *httpHandler) Handle(conn net.Conn) {
} }
u, p, _ := basicProxyAuth(req.Header.Get("Proxy-Authorization")) u, p, _ := basicProxyAuth(req.Header.Get("Proxy-Authorization"))
if Debug && (u != "" || p != "") {
log.Logf("[http] %s - %s : Authorization: '%s' '%s'", conn.RemoteAddr(), req.Host, u, p)
}
if !authenticate(u, p, h.options.Users...) { if !authenticate(u, p, h.options.Users...) {
log.Logf("[http] %s <- %s : proxy authentication required", conn.RemoteAddr(), req.Host) log.Logf("[http] %s <- %s : proxy authentication required", conn.RemoteAddr(), req.Host)
resp := "HTTP/1.1 407 Proxy Authentication Required\r\n" + resp := "HTTP/1.1 407 Proxy Authentication Required\r\n" +
......
...@@ -46,7 +46,6 @@ func (c *http2Connector) Connect(conn net.Conn, addr string) (net.Conn, error) { ...@@ -46,7 +46,6 @@ func (c *http2Connector) Connect(conn net.Conn, addr string) (net.Conn, error) {
Host: addr, Host: addr,
ContentLength: -1, ContentLength: -1,
} }
// req.Header.Set("Gost-Target", addr) // Flag header to indicate the address that server connected to
if c.User != nil { if c.User != nil {
req.Header.Set("Proxy-Authorization", req.Header.Set("Proxy-Authorization",
"Basic "+base64.StdEncoding.EncodeToString([]byte(c.User.String()))) "Basic "+base64.StdEncoding.EncodeToString([]byte(c.User.String())))
...@@ -271,10 +270,7 @@ func (h *http2Handler) Handle(conn net.Conn) { ...@@ -271,10 +270,7 @@ func (h *http2Handler) Handle(conn net.Conn) {
} }
func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) { func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) {
target := r.Header.Get("Gost-Target") target := r.Host
if target == "" {
target = r.Host
}
if !strings.Contains(target, ":") { if !strings.Contains(target, ":") {
target += ":80" target += ":80"
} }
...@@ -294,6 +290,9 @@ func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) { ...@@ -294,6 +290,9 @@ func (h *http2Handler) roundTrip(w http.ResponseWriter, r *http.Request) {
} }
u, p, _ := basicProxyAuth(r.Header.Get("Proxy-Authorization")) u, p, _ := basicProxyAuth(r.Header.Get("Proxy-Authorization"))
if Debug && (u != "" || p != "") {
log.Logf("[http] %s - %s : Authorization: '%s' '%s'", r.RemoteAddr, target, u, p)
}
if !authenticate(u, p, h.options.Users...) { if !authenticate(u, p, h.options.Users...) {
log.Logf("[http2] %s <- %s : proxy authentication required", r.RemoteAddr, target) log.Logf("[http2] %s <- %s : proxy authentication required", r.RemoteAddr, target)
w.Header().Set("Proxy-Authenticate", "Basic realm=\"gost\"") w.Header().Set("Proxy-Authenticate", "Basic realm=\"gost\"")
...@@ -404,8 +403,12 @@ func HTTP2Listener(addr string, config *tls.Config) (Listener, error) { ...@@ -404,8 +403,12 @@ func HTTP2Listener(addr string, config *tls.Config) (Listener, error) {
} }
l.server = server l.server = server
ln, err := tls.Listen("tcp", addr, config)
if err != nil {
return nil, err
}
go func() { go func() {
err := server.ListenAndServeTLS("", "") err := server.Serve(ln)
if err != nil { if err != nil {
log.Log("[http2]", err) log.Log("[http2]", err)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment