-
Created new filter (
ForwardedPrefixFilter) that handles the header and, if present, wrapps it intoPrefixedContextPathRequest(based onHttpServletRequestWrapper) which later on is properly handled if needed, especially intigase.http.jaxrs.ContainerRequestContext#getUriInfo.Crucially, now
uriInfo.getBaseUriBuilder().path("/somepath").build().toString()returns correct path based onX-Forwarded-Prefixvalue.X-Forwarded-Prefixheader is handled as "noun" (sets the prefix for the whole [context] path).For example can be used in nginx configuration:
server { listen 80; server_name admin.tigase.net; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Prefix /; proxy_pass http://localhost:8080/admin/; } }Which will result in
http://admin.tigase.netcorrectly openinghttp://localhost:8080/admin/and providing proper, relative links.Commit: https://tigase.dev/tigase/_server/tigase-http-api/~commits/e141434e391c3abd20f8d78f549660a4f6b1865c
| Type |
New Feature
|
| Priority |
Normal
|
| Assignee | |
| Version |
none
|
| Sprints |
n/a
|
| Customer |
n/a
|
-
tigase-server-8.5.0 Open
Currently, when http-api is behind the proxy and the URI path is change, eg:
Redirects and URIInfo breaks because it operates within context (that maches proxied path). Consider module
test-modulethat has/viewand/loginedpoints. Usually they would be available underhttp://tigase:8080/test-module/viewandhttp://tigase:8080/test-module/loginrespecitvely. However, if we put them behind the proxy they should be available underhttp://module.domain.com/viewandhttp://module.domain.com/login. Unfortunatelly right now the redirect (and all related URIinfo paths) would include context name thus result inhttp://module.domain.com/test-module/login.From what I found most of the projects relay on (unofficial) http header
X-Forwarded-Prefix, for example Spring (https://docs.spring.io/spring-framework/reference/web/webmvc/filters.html#x-forwarded-prefix):