Skip to content

Commit 5c08906

Browse files
committed
revproxy: fix rewriting of request URIs
The request URI lacks the host and a scheme, which we will need to pass the request forward to the origin.
1 parent 68d9e50 commit 5c08906

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

revproxy/revproxy.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,13 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
246246

247247
// rewriteRequest rewrites the inbound request for routing to a target.
248248
func (s *Server) rewriteRequest(pr *httputil.ProxyRequest) {
249-
pr.Out.URL = pr.In.URL
250-
pr.Out.URL.Scheme = "https"
251-
pr.Out.Host = pr.Out.URL.Host
249+
u, _ := url.ParseRequestURI(pr.In.RequestURI)
250+
u.Host = pr.In.Host
251+
if u.Scheme == "" {
252+
u.Scheme = "https"
253+
}
254+
pr.Out.URL = u
255+
pr.Out.Host = u.Host
252256
}
253257

254258
type copyReader struct {

0 commit comments

Comments
 (0)