Skip to content

ServletResponseHttpHeaders ignores content type in ServletResponse #32339

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
dsyer opened this issue Feb 28, 2024 · 0 comments
Closed

ServletResponseHttpHeaders ignores content type in ServletResponse #32339

dsyer opened this issue Feb 28, 2024 · 0 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@dsyer
Copy link
Member

dsyer commented Feb 28, 2024

The Servlet API doesn't say that Content-Type has to be available in ServletResponse.getHeader() and Tomcat actually takes explicit steps to ensure it is not stored as a header (despite being sent as a header to the remote client). So a lot of busywork goes on in Spring if the content type has been set explicitly but is coming back from ServletResponseHttpHeaders as null. Undertow (in contrast) internally chooses to store the content type as a header, so the two servers behave differently and Undertow is faster if the content type is explicitly set.

@sdeleuze sdeleuze self-assigned this Feb 28, 2024
@sdeleuze sdeleuze added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement labels Feb 28, 2024
@sdeleuze sdeleuze added this to the 6.1.5 milestone Feb 28, 2024
@sdeleuze sdeleuze changed the title ServletResponseHttpHeaders ignores content type in ServletResponse ServletResponseHttpHeaders ignores content type in ServletResponse Feb 28, 2024
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 4, 2024
This commit updates ServletServerHttpResponse.ServletResponseHttpHeaders
in order to use ServletResponse#getContentType instead of
ServletResponse#getHeader.

It allows to have a consistent behavior between Tomcat (which set only
the former) and Undertow/Jetty (which set both).

See spring-projectsgh-32339
sdeleuze added a commit to sdeleuze/spring-framework that referenced this issue Mar 4, 2024
This commit avoid calling HttpHeaders#getContentType multiple times in
ServletServerHttpResponse#writeHeaders.

Closes spring-projectsgh-32339
@sdeleuze sdeleuze modified the milestones: 6.1.5, 6.2.0-M1 Mar 4, 2024
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) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants