Skip to content
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

Support headers with multiple values in ResponseStatusException #24261

Closed
KanyCTa opened this issue Dec 24, 2019 · 0 comments
Closed

Support headers with multiple values in ResponseStatusException #24261

KanyCTa opened this issue Dec 24, 2019 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Milestone

Comments

@KanyCTa
Copy link

KanyCTa commented Dec 24, 2019

Affects: Spring-web 5.1.11 & 5.2.1

Spring-web got in version 5.1.11 very useful feature to transfer headers from ResponseExceptions to ResponseStatusExceptionHandler (first mentioned in #23741 and implements in 614c7b0).

Faced with problem: new mechanism can't transfer multivalues headers like

WWW-Authenticate: Negotiate, NTLM

in raw-style (in a Map<String, List<String>> in this case).
ResponseStatusException.getHeaders returns simple java.util.Map.
Nowadays I can transfer multivalues only by converting to delimeted string (for example) and from it in exception handler. Looks lile a bycicle :(

Listing in org.springframework.web.server.ResponseStatusException

/**
 * Return response headers associated with the exception, possibly required
 * for the given status code (e.g. "Allow", "Accept").
 * @since 5.1.11
 */
public Map<String, String> getHeaders() {
    return Collections.emptyMap();
}

Listing in org.springframework.web.server.handler.ResponseStatusExceptionHandler

private boolean updateResponse(ServerHttpResponse response, Throwable ex) {
    boolean result = false;
    HttpStatus status = determineStatus(ex);
    if (status != null) {
        if (response.setStatusCode(status)) {
            if (ex instanceof ResponseStatusException) {
                ((ResponseStatusException) ex).getHeaders()
                        .forEach((name, value) -> response.getHeaders().add(name, value));
            }
            result = true;
        }
    }
    else {
        Throwable cause = ex.getCause();
        if (cause != null) {
            result = updateResponse(response, cause);
        }
    }
    return result;
}

Note, that ServerHttpResponse.getHeaders() returns HttpHeaders that implements MultiValueMap<String, String>

Are any restrictions here for using MultiValueMap in ResponseStatusException.getHeaders() instead of Map?

Seems better to have more flexible mech

@KanyCTa KanyCTa changed the title Fully support of HttpHeaders in ResponseStatusException Support "honest" HttpHeaders in ResponseStatusException Dec 24, 2019
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Dec 24, 2019
@rstoyanchev rstoyanchev self-assigned this Jan 2, 2020
@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 2, 2020
@rstoyanchev rstoyanchev added this to the 5.2.3 milestone Jan 2, 2020
@rstoyanchev rstoyanchev changed the title Support "honest" HttpHeaders in ResponseStatusException Support multiple values response headers via ResponseStatusException Jan 2, 2020
@rstoyanchev rstoyanchev changed the title Support multiple values response headers via ResponseStatusException Support headers with multiple values in ResponseStatusException Jan 2, 2020
@rstoyanchev rstoyanchev added the for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x label Jan 2, 2020
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.1.x Marks an issue as a candidate for backport to 5.1.x labels Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants