Repository: caddyserver/caddy (language: go)

Issue:
httpInclude through proxy with X-Forwarded-For
As discussed in the forum, I am creating this issue to track the progress of the following discussion: https://caddy.community/t/file-server-httpinclude-with-x-forwarded-for/21087

TL;DR:

Goal: Allow the virtual request of `httpInclude` of a `file_server` to include a `RemoteAddr` so that a reverse proxy can set `X-Forwarded-For`.

Otherwise, the `X-Forwarded-For` header is not set and not included in the endpoint that processes the original `httpInclude` request, which is required for applications that trust this header and return different text data depending on its value.



Discussion / hints:
For ref, the fix will need to be applied somewhere in here:

https://github.com/caddyserver/caddy/blob/a306c5f769d876adf1f93d350c8a523b2c3fe760/modules/caddyhttp/templates/tplcontext.go#L186

Fix patch:
diff --git a/modules/caddyhttp/templates/tplcontext.go b/modules/caddyhttp/templates/tplcontext.go
index 6b2b4954d39..a7d53148208 100644
--- a/modules/caddyhttp/templates/tplcontext.go
+++ b/modules/caddyhttp/templates/tplcontext.go
@@ -188,6 +188,7 @@ func (c TemplateContext) funcHTTPInclude(uri string) (string, error) {
 		return "", err
 	}
 	virtReq.Host = c.Req.Host
+	virtReq.RemoteAddr = "127.0.0.1:10000" // https://github.com/caddyserver/caddy/issues/5835
 	virtReq.Header = c.Req.Header.Clone()
 	virtReq.Header.Set("Accept-Encoding", "identity") // https://github.com/caddyserver/caddy/issues/4352
 	virtReq.Trailer = c.Req.Trailer.Clone()


Test patch: