diff --git a/cmd/gost/route.go b/cmd/gost/route.go index deb71cf..7ebbdf9 100644 --- a/cmd/gost/route.go +++ b/cmd/gost/route.go @@ -665,6 +665,7 @@ func (r *route) GenRouters() ([]router, error) { gost.TCPModeHandlerOption(node.GetBool("tcp")), gost.IPRoutesHandlerOption(tunRoutes...), gost.ProxyAgentHandlerOption(node.Get("proxyAgent")), + gost.HTTPTunnelHandlerOption(node.GetBool("httpTunnel")), ) rt := router{ diff --git a/handler.go b/handler.go index 81f505f..ee82cea 100644 --- a/handler.go +++ b/handler.go @@ -43,6 +43,7 @@ type HandlerOptions struct { TCPMode bool IPRoutes []IPRoute ProxyAgent string + HTTPTunnel bool } // HandlerOption allows a common way to set handler options. @@ -219,6 +220,13 @@ func ProxyAgentHandlerOption(agent string) HandlerOption { } } +// HTTPTunnelHandlerOption sets the Tunnel mode for HTTP client used in HTTP handler. +func HTTPTunnelHandlerOption(tunnelMode bool) HandlerOption { + return func(opts *HandlerOptions) { + opts.HTTPTunnel = tunnelMode + } +} + type autoHandler struct { options *HandlerOptions } diff --git a/http.go b/http.go index 3275daa..02a7ad3 100644 --- a/http.go +++ b/http.go @@ -257,7 +257,9 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) { // forward http request lastNode := route.LastNode() - if req.Method != http.MethodConnect && lastNode.Protocol == "http" { + if req.Method != http.MethodConnect && + lastNode.Protocol == "http" && + !h.options.HTTPTunnel { err = h.forwardRequest(conn, req, route) if err == nil { return