Skip to content

Remove Content-Length response header before delegating to WebExceptionHandlers [SPR-17502] #22034

@spring-projects-issues

Description

@spring-projects-issues

Brian Clozel opened SPR-17502 and commented

Given the following controller in Spring WebFlux:

@RestController
public class TestController {

	@GetMapping(path = "/", produces = MediaType.TEXT_PLAIN_VALUE)
	public Flux<String> text(ServerWebExchange exchange) {
		exchange.getResponse().getHeaders().setContentLength(12);
		return Flux.error(new IllegalStateException());
	}
}

When this handler is used, the thrown exception is being handled by the WebExceptionHandlers configured instances. At that point, the response might be committed or not.

When used in Spring Boot, this will cause HTTP clients to partially read the actual error response (JSON or HTML), since those are written in chunked encoding mode. Also, other encoders will opt out and won't override any existing "Content-Length" header.

We should (in ExceptionHandlingWebHandler ?) make sure that we try and remove the "Content-Length" response header as the error response won't be of the same length.


Affects: 5.0.10, 5.1.2

Referenced from: commits 617b94a, 3203d39, 5342c6e

Backported to: 5.0.11

1 votes, 4 watchers

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions