mirror of https://github.com/caddyserver/caddy.git
adapt ForwardProxyURL to use the NetworkProxyRaw
Signed-off-by: Mohammed Al Sahaf <msaa1990@gmail.com>
This commit is contained in:
parent
908fa5e103
commit
b8a9870410
|
@ -0,0 +1,41 @@
|
|||
:8884
|
||||
reverse_proxy 127.0.0.1:65535 {
|
||||
transport http {
|
||||
forward_proxy_url http://localhost:8080
|
||||
}
|
||||
}
|
||||
----------
|
||||
{
|
||||
"apps": {
|
||||
"http": {
|
||||
"servers": {
|
||||
"srv0": {
|
||||
"listen": [
|
||||
":8884"
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"handle": [
|
||||
{
|
||||
"handler": "reverse_proxy",
|
||||
"transport": {
|
||||
"network_proxy": {
|
||||
"from": "url",
|
||||
"url": "http://localhost:8080"
|
||||
},
|
||||
"protocol": "http"
|
||||
},
|
||||
"upstreams": [
|
||||
{
|
||||
"dial": "127.0.0.1:65535"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/caddyserver/caddy/v2/modules/caddyhttp/headers"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddytls"
|
||||
"github.com/caddyserver/caddy/v2/modules/internal/network"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -1078,8 +1079,8 @@ func (h *HTTPTransport) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
|||
if !d.NextArg() {
|
||||
return d.ArgErr()
|
||||
}
|
||||
|
||||
h.ForwardProxyURL = d.Val()
|
||||
u := network.ProxyFromURL{URL: d.Val()}
|
||||
h.NetworkProxyRaw = caddyconfig.JSONModuleObject(u, "from", "url", nil)
|
||||
|
||||
case "network_proxy":
|
||||
if !d.NextArg() {
|
||||
|
|
|
@ -24,7 +24,6 @@ import (
|
|||
weakrand "math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
@ -36,8 +35,10 @@ import (
|
|||
"golang.org/x/net/http2"
|
||||
|
||||
"github.com/caddyserver/caddy/v2"
|
||||
"github.com/caddyserver/caddy/v2/caddyconfig"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
|
||||
"github.com/caddyserver/caddy/v2/modules/caddytls"
|
||||
"github.com/caddyserver/caddy/v2/modules/internal/network"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -344,6 +345,11 @@ func (h *HTTPTransport) NewTransport(caddyCtx caddy.Context) (*http.Transport, e
|
|||
|
||||
// negotiate any HTTP/SOCKS proxy for the HTTP transport
|
||||
proxy := http.ProxyFromEnvironment
|
||||
if h.ForwardProxyURL != "" {
|
||||
caddyCtx.Logger().Warn("forward_proxy_url is deprecated; use network_proxy instead")
|
||||
u := network.ProxyFromURL{URL: h.ForwardProxyURL}
|
||||
h.NetworkProxyRaw = caddyconfig.JSONModuleObject(u, "from", "url", nil)
|
||||
}
|
||||
if len(h.NetworkProxyRaw) != 0 {
|
||||
proxyMod, err := caddyCtx.LoadModule(h, "ForwardProxyRaw")
|
||||
if err != nil {
|
||||
|
@ -356,16 +362,6 @@ func (h *HTTPTransport) NewTransport(caddyCtx caddy.Context) (*http.Transport, e
|
|||
}
|
||||
}
|
||||
|
||||
if h.ForwardProxyURL != "" {
|
||||
caddyCtx.Logger().Warn("forward_proxy_url is deprecated; use network_proxy instead")
|
||||
pUrl, err := url.Parse(h.ForwardProxyURL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse transport proxy url: %v", err)
|
||||
}
|
||||
caddyCtx.Logger().Info("setting transport proxy url", zap.String("url", h.ForwardProxyURL))
|
||||
proxy = http.ProxyURL(pUrl)
|
||||
}
|
||||
|
||||
rt := &http.Transport{
|
||||
Proxy: proxy,
|
||||
DialContext: dialContext,
|
||||
|
|
Loading…
Reference in New Issue