HTTPのリバースプロキシが本来のパスを伝えるためのヘッダ - X-Forwarded-Prefix
#X-Forwarded-Prefix #HTTP #リバースプロキシ #reverse_proxy
リバースプロキシが受け取ったHTTPのリクエストのパス(GET <ここの部分> HTTP/1.1)をupstreamのサーバーに伝える時のヘッダにX-Forwarded-Prefixを使うことが広く使わされていることが分かった。
X-Forwarded-Prefixの情報は現段階では少ない。X-Forwarded-Prefixは非標準のヘッダ。
調査
Microsoft YARP
Microsoftが作るリバースプロキシ YARPではこのヘッダに対応している。
X-Forwarded-Prefix - Sets the request's original PathBase, if any, to the X-Forwarded-Prefix header. See X-Forwarded below.
https://github.com/microsoft/reverse-proxy/blob/a99eb328140e4e11885a1bbd35e849df7ce7fe85/docs/docfx/articles/transforms.md#L16
YARPもかつてはX-Forwarded-PathBaseとこのヘッダを呼んでいた時もあったよう。以下のプルリクエストで改名されている。
https://github.com/microsoft/reverse-proxy/issues/737
改名される決断にも関係している調査が以下のGitHubコメント。
https://github.com/dotnet/aspnetcore/issues/23263#issuecomment-776192575
Kubernetes NGINX Ingress Controller
To add the non-standard X-Forwarded-Prefix header to the upstream request with a string value, the following annotation can be used:
https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#x-forwarded-prefix-header
https://github.com/kubernetes/ingress-nginx/issues/7880#issue-1044189354
Spring
以下の通り、非標準であるX-Forwarded-Prefixも存在してると書かれている。
There are other non-standard headers, too, including X-Forwarded-Host, X-Forwarded-Port, X-Forwarded-Proto, X-Forwarded-Ssl, and X-Forwarded-Prefix.
https://github.com/spring-projects/spring-framework/blob/3600644ed1776dce35c4a42d74799a90b90e359e/src/docs/asciidoc/web/webmvc.adoc#L1341
Gin
https://github.com/gin-gonic/gin/blob/fb5f0454178756d8040f9224092319febc3853b8/gin.go#L652
Appache Camel
https://github.com/apache/camel/blob/7303e3102c5f78794f7350387c2339bde58110cd/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiSupportTest.java#L51
Kong
New function kong.request.get_forwarded_prefix: returns the prefix path component of the request's URL that Kong stripped before proxying to upstream, respecting the value of X-Forwarded-Prefix when it comes from a trusted source
https://github.com/Kong/kong/blob/fd8a2233e179c7ec79e2af155c24616c9a8d6e71/CHANGELOG.md#L1304
https://github.com/traefik/traefik/search?q=X-Forwarded-Prefix
その他
その他のヘッダ名としてX-Forwarded-PathBaseが上記でも登場したが、その他のヘッダに関して。
Envoyには以下のヘッダがある。
x-envoy-original-path
https://github.com/envoyproxy/envoy/issues/5528#issuecomment-452157746