Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproxy Support for X-Forwarded Headers #173

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ In case if rules set as a part of docker compose environment, destination with t

## SSL support

SSL mode (by default none) can be set to `auto` (ACME/LE certificates), `static` (existing certificate) or `none`. If `auto` turned on SSL certificate will be issued automatically for all discovered server names. User can override it by setting `--ssl.fqdn` value(s)
SSL mode (by default none) can be set to `auto` (ACME/LE certificates), `static` (existing certificate) or `none`. If `auto` turned on SSL certificate will be issued automatically for all discovered server names. User can override it by setting `--ssl.fqdn` value(s). In `auto` and `static` SSL mode, Reproxy will automatically add the `X-Forwarded-Proto` and `X-Forwarded-Port` headers. These headers are useful for services behind the proxy to know the original protocol (http or https) and port number used by the client.

umputun marked this conversation as resolved.
Show resolved Hide resolved
## Headers

Expand Down
4 changes: 4 additions & 0 deletions app/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ func (h *Http) proxyHandler() http.HandlerFunc {
uu := ctx.Value(ctxURL).(*url.URL)
keepHost := ctx.Value(ctxKeepHost).(bool)
r.Header.Add("X-Forwarded-Host", r.Host)
if h.SSLConfig.SSLMode == SSLAuto || h.SSLConfig.SSLMode == SSLStatic {
r.Header.Add("X-Forwarded-Proto", "https")
r.Header.Add("X-Forwarded-Port", "443")
}
r.URL.Path = uu.Path
r.URL.Host = uu.Host
r.URL.Scheme = uu.Scheme
Expand Down
2 changes: 2 additions & 0 deletions app/proxy/proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func TestHttp_Do(t *testing.T) {
w.Header().Add("h1", "v1")
require.Equal(t, "127.0.0.1", r.Header.Get("X-Real-IP"))
require.Equal(t, "127.0.0.1", r.Header.Get("X-Forwarded-For"))
require.Empty(t, r.Header.Get("X-Forwarded-Proto")) // ssl auto only
require.Empty(t, r.Header.Get("X-Forwarded-Port"))
fmt.Fprintf(w, "response %s", r.URL.String())
}))

Expand Down
Loading