Skip to content

Commit 518ca2c

Browse files
authored
ReverseProxy: use Rewrite to replace Director (fatedier#4005)
* display go version in make * ReverseProxy: use Rewrite to replace Director
1 parent 4957fd2 commit 518ca2c

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export PATH := $(GOPATH)/bin:$(PATH)
1+
export PATH := $(PATH):`go env GOPATH`/bin
22
export GO111MODULE=on
33
LDFLAGS := -s -w
44

pkg/plugin/client/http2https.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ func NewHTTP2HTTPSPlugin(options v1.ClientPluginOptions) (Plugin, error) {
5353
}
5454

5555
rp := &httputil.ReverseProxy{
56-
Director: func(req *http.Request) {
56+
Rewrite: func(r *httputil.ProxyRequest) {
57+
req := r.Out
5758
req.URL.Scheme = "https"
5859
req.URL.Host = p.opts.LocalAddr
5960
if p.opts.HostHeaderRewrite != "" {

pkg/plugin/client/https2http.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ func NewHTTPS2HTTPPlugin(options v1.ClientPluginOptions) (Plugin, error) {
5050
}
5151

5252
rp := &httputil.ReverseProxy{
53-
Director: func(req *http.Request) {
53+
Rewrite: func(r *httputil.ProxyRequest) {
54+
req := r.Out
5455
req.URL.Scheme = "http"
5556
req.URL.Host = p.opts.LocalAddr
5657
if p.opts.HostHeaderRewrite != "" {

pkg/plugin/client/https2https.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func NewHTTPS2HTTPSPlugin(options v1.ClientPluginOptions) (Plugin, error) {
5555
}
5656

5757
rp := &httputil.ReverseProxy{
58-
Director: func(req *http.Request) {
58+
Rewrite: func(r *httputil.ProxyRequest) {
59+
req := r.Out
5960
req.URL.Scheme = "https"
6061
req.URL.Host = p.opts.LocalAddr
6162
if p.opts.HostHeaderRewrite != "" {

pkg/util/vhost/http.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
5858
}
5959
proxy := &httputil.ReverseProxy{
6060
// Modify incoming requests by route policies.
61-
Director: func(req *http.Request) {
61+
Rewrite: func(r *httputil.ProxyRequest) {
62+
r.SetXForwarded()
63+
req := r.Out
6264
req.URL.Scheme = "http"
6365
reqRouteInfo := req.Context().Value(RouteInfoKey).(*RequestRouteInfo)
6466
oldHost, _ := httppkg.CanonicalHost(reqRouteInfo.Host)

0 commit comments

Comments
 (0)