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

WebFlux commitActions are called after status, headers and cookies are set [SPR-16597] #21138

Closed
spring-issuemaster opened this Issue Mar 15, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

spring-issuemaster commented Mar 15, 2018

Nicolas Portmann opened SPR-16597 and commented

ServerHttpResponse allows commitActions to be added (e.g. inside a WebFilter) via the beforeCommit method.

AbstractHttpServerResponse however calls the protected methods applyStatusCode(), applyHeaders() and applyCookies() synchronously before the Mono<Void>s passed as commitActions get executed. This makes it impossible to change the status code, add headers or cookies in beforeCommit actions asynchonously. A use case for this would be to add values from the subscriber context to the response headers.

AbstractHttpServerResponse#doCommit should wrap the calls to the applyXXX() methods in a mono which is subscribed to after the other commitActions.

Current code:

this.commitAction.add(() -> {
    applyStatusCode();
    applyHeaders();
    applyCookies();
    // ...
    return Mono.empty();
});

Proposed solution:

this.commitActions.add(() -> {
    Mono.fromRunnable(() -> {
        applyStatusCode();
        applyHeaders();
        applyCookies();
        // ...
    });
});

Affects: 5.0.4

Issue Links:

  • #21882 Send static file action is invoked before applying the relevant headers

Referenced from: commits 72bbb26

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Mar 15, 2018

Nicolas Portmann commented

It looks as if this behavioral change was introduced in 9f8e845

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

spring-issuemaster commented Mar 16, 2018

Rossen Stoyanchev commented

Well spotted, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment