Browse Source

#889: add http tunnel mode for HTTP handler

pull/934/head
ginuerzh 4 years ago
parent
commit
005cff5888
  1. 1
      cmd/gost/route.go
  2. 8
      handler.go
  3. 4
      http.go

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

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

4
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

Loading…
Cancel
Save