Skip to content

Commit

Permalink
ReverseProxy: use Rewrite to replace Director (#4005)
Browse files Browse the repository at this point in the history
* display go version in make

* ReverseProxy: use Rewrite to replace Director
  • Loading branch information
fatedier authored Feb 19, 2024
1 parent 4957fd2 commit 518ca2c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export PATH := $(GOPATH)/bin:$(PATH)
export PATH := $(PATH):`go env GOPATH`/bin
export GO111MODULE=on
LDFLAGS := -s -w

Expand Down
3 changes: 2 additions & 1 deletion pkg/plugin/client/http2https.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ func NewHTTP2HTTPSPlugin(options v1.ClientPluginOptions) (Plugin, error) {
}

rp := &httputil.ReverseProxy{
Director: func(req *http.Request) {
Rewrite: func(r *httputil.ProxyRequest) {
req := r.Out
req.URL.Scheme = "https"
req.URL.Host = p.opts.LocalAddr
if p.opts.HostHeaderRewrite != "" {
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugin/client/https2http.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func NewHTTPS2HTTPPlugin(options v1.ClientPluginOptions) (Plugin, error) {
}

rp := &httputil.ReverseProxy{
Director: func(req *http.Request) {
Rewrite: func(r *httputil.ProxyRequest) {
req := r.Out
req.URL.Scheme = "http"
req.URL.Host = p.opts.LocalAddr
if p.opts.HostHeaderRewrite != "" {
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugin/client/https2https.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ func NewHTTPS2HTTPSPlugin(options v1.ClientPluginOptions) (Plugin, error) {
}

rp := &httputil.ReverseProxy{
Director: func(req *http.Request) {
Rewrite: func(r *httputil.ProxyRequest) {
req := r.Out
req.URL.Scheme = "https"
req.URL.Host = p.opts.LocalAddr
if p.opts.HostHeaderRewrite != "" {
Expand Down
4 changes: 3 additions & 1 deletion pkg/util/vhost/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func NewHTTPReverseProxy(option HTTPReverseProxyOptions, vhostRouter *Routers) *
}
proxy := &httputil.ReverseProxy{
// Modify incoming requests by route policies.
Director: func(req *http.Request) {
Rewrite: func(r *httputil.ProxyRequest) {
r.SetXForwarded()
req := r.Out
req.URL.Scheme = "http"
reqRouteInfo := req.Context().Value(RouteInfoKey).(*RequestRouteInfo)
oldHost, _ := httppkg.CanonicalHost(reqRouteInfo.Host)
Expand Down

0 comments on commit 518ca2c

Please sign in to comment.