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

ResourceServlet commits response preventing filters from modifying response headers after filterChain.doFilter - regression from Jetty 11 #12766

Open
Spikhalskiy opened this issue Feb 4, 2025 · 2 comments
Labels
Bug For general bugs on Jetty side

Comments

@Spikhalskiy
Copy link

Spikhalskiy commented Feb 4, 2025

Jetty version(s)
Jetty 12.0.16

Jetty Environment
EE10

Description

I'm migrating from Jetty 11 to Jetty 12 and noticed a regression. Headers set by our Filters after a call to filterChain.doFilter are missing or incorrect on certain URLs without any debug logging.
I was able to trace it to the fact that ResourceServlet is committing the response here:

	at org.eclipse.jetty.server.ResourceService.writeHttpContent(ResourceService.java:718)
	at org.eclipse.jetty.server.ResourceService.sendData(ResourceService.java:670) //response.write(true, buffer, callback);
	at org.eclipse.jetty.server.ResourceService.doGet(ResourceService.java:206)
	at org.eclipse.jetty.ee10.servlet.ResourceServlet.doGet(ResourceServlet.java:530)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:527)
	at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:614)
	at org.eclipse.jetty.ee10.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1379)
	at org.eclipse.jetty.ee10.servlet.ServletHolder.handle(ServletHolder.java:736)
	at org.eclipse.jetty.ee10.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1619)

After which modification of response headers in the filters after filterChain.doFilter() call are silently ignored in ServletContextResponse. For example:

@Override
public boolean onRemoveField(HttpField field) {
            if (isCommitted())
                return false;

This looks like a regression from Jetty 11, as the filters were able to correctly modify the headers of the response with Jetty 11.
Could ResourceServlet / ResourceService not commit the response to let the filters do their job?

For additional context, this issue was hard to track and untangle because of the silent discarding of header modification. It would be nice to have at least a debug log if the header or status modification was rejected inside Jetty code because the response is already committed.

Test

I modified ResourceServletTest#testOutputStreamAndCharsetFiltered to reproduce the issue:
Spikhalskiy@8054950

@Spikhalskiy Spikhalskiy added the Bug For general bugs on Jetty side label Feb 4, 2025
@Spikhalskiy Spikhalskiy changed the title ResourceServlet commits response preventing filters from modifying response headers after doFilter - regression from Jetty 11 ResourceServlet commits response preventing filters from modifying response headers after filterChain.doFilter - regression from Jetty 11 Feb 4, 2025
@joakime
Copy link
Contributor

joakime commented Feb 4, 2025

Agreed, a flush/commit from a servlet should have no impact on if a filter is executed or not.

Spikhalskiy added a commit to Spikhalskiy/jetty.project that referenced this issue Feb 5, 2025
@Spikhalskiy
Copy link
Author

Spikhalskiy commented Feb 5, 2025

I added a reproduction within Jetty tests to make it easier to diagnose:
Spikhalskiy@8054950

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
Status: No status
Development

No branches or pull requests

2 participants