Skip to content

Add support for HeaderWriterFilter to write headers at the beginning of the request #6501

Closed
@jzheaux

Description

@jzheaux

Related to #6414

Let's add some support to HeaderWriterFilter for writing headers at the beginning of the request:

public void setShouldWriteHeadersEagerly(boolean shouldWriteHeadersEagerly) {
    this.shouldWriteHeadersEagerly = shouldWriteHeadersEagerly;
}

Which would then allow folks to post process the HeaderWriterFilter and configure it:

http
    .headers()
        .withObjectPostProcessor(new ObjectPostProcessor<HeaderWriterFilter>() {
            public HeaderWriterFilter postProcess(HeaderWriterFilter filter) {
                filter.setShouldWriteHeadersEagerly(true);
                return filter;
            }
        }  

HeaderWriterFilter writes headers at the end of the request. However, headers cannot be written after an include.

If the user uses servletContext.getRequestDispatcher(path).include(request, response), for example, then the security headers will not get written.

Spring Security is able to wrap HttpServletRequest so that request.getRequestDispatcher(path).include(request, response) is captured, but it is not possible to do the same with ServletContext.

Metadata

Metadata

Assignees

Labels

in: webAn issue in web modules (web, webmvc)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions