Skip to content

PagedResourcesAssembler.getDefaultUriString() does not handle protocol properly (proxy) #260

@matthewdfleming

Description

@matthewdfleming

The following code gets called at some point in the linkTo(methodOn... sequence:

private UriComponents getDefaultUriString() {
    return baseUri == null ? ServletUriComponentsBuilder.fromCurrentRequest().build() : baseUri;
}

This code doesn't deal with the protocol properly when proxied. So what I have is that some of my links are http and others are https. The links that happen via the ControllerLinkBuilderFactory are correct as they use the ControllerLinkBuilder.getBuilder() method that understands the "X-Forwarded-Ssl" header (which we are including in our virtual host).

I haven't fully tested but what seems to be working properly is the following (instead):

private UriComponents getDefaultUriString() {
    return baseUri == null ? getBuilder().build() : baseUri;
}

private static UriComponentsBuilder getBuilder() {

    HttpServletRequest request = getCurrentRequest();
    ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(request);
...

The rest of the getBuilder() and getCurrentRequest() methods are monkey patched/copied from the ControllerLinkBuilder.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions