Skip to content

Commit

Permalink
Check for x-forwarded-proto when constructing API base url
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbarnett91 committed Nov 21, 2023
1 parent 6f98a16 commit 9cb9319
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/main/java/uk/gov/beis/els/api/openapi/OpenApiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
import org.springframework.web.util.UriComponentsBuilder;
import uk.gov.beis.els.api.common.ApiDocumentationController;
import uk.gov.beis.els.api.common.TagNotFoundException;
import uk.gov.beis.els.api.model.OperationWithSchema;
Expand Down Expand Up @@ -66,9 +67,15 @@ public String getApiSpecUrl(HttpServletRequest request) {
}

public String getBaseUrl(HttpServletRequest request) {
return ServletUriComponentsBuilder.fromRequestUri(request)
.replacePath(null)
.build()
UriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(request)
.replacePath(null);

String xForwardedProto = request.getHeader("X-Forwarded-Proto");
if (xForwardedProto != null) {
builder.scheme(xForwardedProto);
}

return builder.build()
.toUriString();
}

Expand Down

0 comments on commit 9cb9319

Please sign in to comment.