Skip to content

Documentation for ForwardedHeaderFilter does not mention important filter order #23954

@ctytgat

Description

@ctytgat

Affects: 5.1.10

It took me half a day to figure out why my spring hateoas / ForwardedHeaderFilter setup did not work as intended.

It appeared that the HttpServletRequest used by ServletUriComponentsBuilder wasn't the wrapped one, which is caused by the fact that ForwardedHeaderFilter was executed AFTER RequestContextFilter.

You basically need to do this:

    @Bean
    public FilterRegistrationBean forwardedHeaderFilterRegistrationBean() {

        FilterRegistrationBean<ForwardedHeaderFilter> registrationBean = new FilterRegistrationBean<>();

        registrationBean.setFilter(new ForwardedHeaderFilter());
        registrationBean.addUrlPatterns("*");
        registrationBean.setOrder(org.springframework.boot.web.servlet.filter.OrderedFilter.REQUEST_WRAPPER_FILTER_MAX_ORDER - 1);

        return registrationBean;
    }

I didn't find any mention of this in the docs...

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: documentationA documentation task

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions