@@ -27,6 +27,7 @@ type proxyPassConfig struct {
27
27
ResponseHandler []responseHandler
28
28
ErrorHandler errorHandler
29
29
Transport http.RoundTripper
30
+ UseTargetHost bool
30
31
}
31
32
32
33
func (ppc * proxyPassConfig ) appendResponseHandler (handler responseHandler ) {
@@ -77,12 +78,14 @@ func joinURLPath(a, b *url.URL) (path, rawpath string) {
77
78
return a .Path + b .Path , apath + bpath
78
79
}
79
80
80
- func NewSingleHostReverseProxy (target * url.URL ) * httputil.ReverseProxy {
81
+ func NewSingleHostReverseProxy (target * url.URL , useTargetHost bool ) * httputil.ReverseProxy {
81
82
targetQuery := target .RawQuery
82
83
director := func (req * http.Request ) {
83
84
req .URL .Scheme = target .Scheme
84
85
req .URL .Host = target .Host
85
- req .Host = target .Host
86
+ if useTargetHost {
87
+ req .Host = target .Host
88
+ }
86
89
req .URL .Path , req .URL .RawPath = joinURLPath (target , req .URL )
87
90
if targetQuery == "" || req .URL .RawQuery == "" {
88
91
req .URL .RawQuery = targetQuery + req .URL .RawQuery
@@ -130,7 +133,7 @@ func proxyPass(config *RouteHandlerConfig, infoProvider WorkspaceInfoProvider, r
130
133
131
134
// TODO(cw): we should cache the proxy for some time for each target URL
132
135
133
- proxy := NewSingleHostReverseProxy (targetURL )
136
+ proxy := NewSingleHostReverseProxy (targetURL , h . UseTargetHost )
134
137
proxy .Transport = h .Transport
135
138
proxy .ModifyResponse = func (resp * http.Response ) error {
136
139
url := resp .Request .URL
@@ -248,6 +251,12 @@ func withXFrameOptionsFilter() proxyPassOpt {
248
251
}
249
252
}
250
253
254
+ func withUseTargetHost () proxyPassOpt {
255
+ return func (cfg * proxyPassConfig ) {
256
+ cfg .UseTargetHost = true
257
+ }
258
+ }
259
+
251
260
type workspaceTransport struct {
252
261
transport http.RoundTripper
253
262
}
0 commit comments