#889: add http tunnel mode for HTTP handler
This commit is contained in:
parent
aa8312a902
commit
005cff5888
@ -665,6 +665,7 @@ func (r *route) GenRouters() ([]router, error) {
|
|||||||
gost.TCPModeHandlerOption(node.GetBool("tcp")),
|
gost.TCPModeHandlerOption(node.GetBool("tcp")),
|
||||||
gost.IPRoutesHandlerOption(tunRoutes...),
|
gost.IPRoutesHandlerOption(tunRoutes...),
|
||||||
gost.ProxyAgentHandlerOption(node.Get("proxyAgent")),
|
gost.ProxyAgentHandlerOption(node.Get("proxyAgent")),
|
||||||
|
gost.HTTPTunnelHandlerOption(node.GetBool("httpTunnel")),
|
||||||
)
|
)
|
||||||
|
|
||||||
rt := router{
|
rt := router{
|
||||||
|
@ -43,6 +43,7 @@ type HandlerOptions struct {
|
|||||||
TCPMode bool
|
TCPMode bool
|
||||||
IPRoutes []IPRoute
|
IPRoutes []IPRoute
|
||||||
ProxyAgent string
|
ProxyAgent string
|
||||||
|
HTTPTunnel bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandlerOption allows a common way to set handler options.
|
// 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 {
|
type autoHandler struct {
|
||||||
options *HandlerOptions
|
options *HandlerOptions
|
||||||
}
|
}
|
||||||
|
4
http.go
4
http.go
@ -257,7 +257,9 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
|
|||||||
|
|
||||||
// forward http request
|
// forward http request
|
||||||
lastNode := route.LastNode()
|
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)
|
err = h.forwardRequest(conn, req, route)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user