diff options
author | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-09-06 11:50:26 +0200 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@verizonmedia.com> | 2021-09-06 11:50:26 +0200 |
commit | eb149c8cd40cdd86e24e70ad934d2cbb05d0ad05 (patch) | |
tree | 7a3fca548284e415df278427362a976f8e6c4612 /container-core/src | |
parent | e921015d09d63e434bf618e63bb66cb34832c2e1 (diff) |
Support 'X-Forwarded-Host'
Diffstat (limited to 'container-core/src')
-rw-r--r-- | container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java b/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java index 68459cdb89d..bba79dbfad4 100644 --- a/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java +++ b/container-core/src/main/java/com/yahoo/restapi/RestApiImpl.java @@ -400,9 +400,16 @@ class RestApiImpl implements RestApi { @Override public ObjectMapper jacksonJsonMapper() { return jacksonJsonMapper; } @Override public UriBuilder uriBuilder() { URI uri = request.getUri(); + // Reconstruct the URI used by the client to access the API. + // This is needed for producing URIs in the response that links to other parts of the Rest API. + // request.getUri() cannot be used as its port is the local listen port (as it's intended for request routing). StringBuilder sb = new StringBuilder(uri.getScheme()).append("://"); - if (request.getHeader("Host") != null) { - sb.append(request.getHeader("Host")); + String hostHeader = request.getHeader("X-Forwarded-Host"); + if (hostHeader == null || hostHeader.isBlank()) { + hostHeader = request.getHeader("Host"); + } + if (hostHeader != null && !hostHeader.isBlank()) { + sb.append(hostHeader); } else { sb.append(uri.getHost()); if (uri.getPort() > 0) { |