#889: add http tunnel mode for HTTP handler

This commit is contained in:
ginuerzh 2022-11-16 15:21:01 +08:00
parent aa8312a902
commit 005cff5888
3 changed files with 12 additions and 1 deletions

View File

@ -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{

View File

@ -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
}

View File

@ -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