Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jzheaux opened this issue Feb 1, 2019 · 3 comments
Assignees
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement

Comments

@jzheaux
Copy link
Contributor

jzheaux commented Feb 1, 2019

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.

@ankurpathak
Copy link
Contributor

I would like to take this one.

@jzheaux
Copy link
Contributor Author

jzheaux commented Feb 5, 2019

It's yours, @ankurpathak!

@jzheaux jzheaux removed the status: ideal-for-contribution An issue that we actively are looking for someone to help us with label Feb 5, 2019
@jzheaux jzheaux self-assigned this Feb 5, 2019
@ankurpathak
Copy link
Contributor

Pull request for the issue:
#6509

ankurpathak added a commit to ankurpathak/spring-security that referenced this issue Feb 13, 2019
Add support for HeaderWriterFilter to write headers at the beginning of the request

Fixes: spring-projectsgh-6501
jzheaux added a commit that referenced this issue Feb 18, 2019
In the Java config tests, there is a simplified way to configure
Spring, and that is with SpringTestRule.

Also, test names typically follow the when-then convention.

Issue: gh-6501
@rwinch rwinch added the type: enhancement A general enhancement label May 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web An issue in web modules (web, webmvc) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants