Skip to content

Headers were lost when returning a null StreamingResponseBody within a ResponseEntity [SPR-14315] #18887

@spring-projects-issues

Description

@spring-projects-issues

Lifu Zhou opened SPR-14315 and commented

If a controller method's specification were:

public ResponseEntity<StreamingResponseBody> foo(){
    //  code...
}

and returns:

return new ResponseEntity<StreamingResponseBody>(someHeaders, HttpStatus.OK);

Then, the headers would be lost because they weren't flushed after not null check:

//  StreamingResponseBodyReturnValueHandler#handleReturnValue
if (ResponseEntity.class.isAssignableFrom(returnValue.getClass())) {
	ResponseEntity<?> responseEntity = (ResponseEntity<?>) returnValue;
	outputMessage.setStatusCode(responseEntity.getStatusCode());
	outputMessage.getHeaders().putAll(responseEntity.getHeaders());

	returnValue = responseEntity.getBody();
	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;		// <--- here, return directly without flushing headers. 
	}
}

But I'm not sure it was intentional or just a oversight ;)


Affects: 4.3 RC2

Referenced from: commits 22c260f, 7e95cd8, f20f6c9

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions