-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Jetty 12 throws Exception handling static files when using response wrapper #10463
Comments
You had a Response.Wrapper where you set the response header Seems like an expected outcome / result in this situation. What were you expecting to happen? |
@joakime I didn't set the content-length to a date string in the response wrapper. It is the method content.getLastModified() returned a value 'Wed, 31 May 2023 16:15:38 GMT' . |
@janbartel Thanks! |
Fixed via #10556 |
Jetty version(s)
Jetty 12
Jetty Environment
EE8
Java version/vendor
(use: java -version)
openjdk 17
OS type/version
Description
How to reproduce?
Wheh user uses response wrapper to wrap the response for static files, there will be an exception:
java.lang.NumberFormatException: For input string: "Wed, 31 May 2023 16:15:38 GMT"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Long.parseLong(Long.java:711)
at java.base/java.lang.Long.parseLong(Long.java:836)
at org.eclipse.jetty.http.HttpField.getLongValue(HttpField.java:355)
at org.eclipse.jetty.ee8.nested.Response.putHeaders(Response.java:1198)
at org.eclipse.jetty.ee8.nested.ResourceService.putHeaders(ResourceService.java:717)
at org.eclipse.jetty.ee8.nested.ResourceService.sendData(ResourceService.java:569)
at org.eclipse.jetty.ee8.nested.ResourceService.doGet(ResourceService.java:279)
at org.eclipse.jetty.ee8.servlet.DefaultServlet.doGet(DefaultServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:503)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:590)
at org.eclipse.jetty.ee8.servlet.ServletHolder$NotAsync.service(ServletHolder.java:1145)
at org.eclipse.jetty.ee8.servlet.ServletHolder.handle(ServletHolder.java:640)
at org.eclipse.jetty.ee8.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1373)
The cause is that I used a response wrapper to wrap the response before it is returned.
In ResourceService.putHeaders, if the response is not an instance of Response , Response.putHeaders will be called:
protected void putHeaders(HttpServletResponse response, HttpContent content, long contentLength) {
if (response instanceof Response r) {
r.putHeaders(content, contentLength, _etags);
HttpFields.Mutable fields = r.getHttpFields();
if (_acceptRanges && !fields.contains(HttpHeader.ACCEPT_RANGES))
fields.add(ACCEPT_RANGES);
if (_cacheControl != null && !fields.contains(HttpHeader.CACHE_CONTROL))
fields.add(_cacheControl);
} else {
Response.putHeaders(response, content, contentLength, _etags);<================================
if (_acceptRanges && !response.containsHeader(HttpHeader.ACCEPT_RANGES.asString()))
response.setHeader(ACCEPT_RANGES.getName(), ACCEPT_RANGES.getValue());
if (_cacheControl != null && !response.containsHeader(HttpHeader.CACHE_CONTROL.asString()))
response.setHeader(_cacheControl.getName(), _cacheControl.getValue());
}
}
This line:
public static void putHeaders(HttpServletResponse response, HttpContent content, long contentLength, boolean etag) {
long lml = content.getLastModified().getLongValue();<================================
Throws an exception if the getLastModified() returns a Date String instead of a long String.
Could you please help check if this needs to be fixed?
Thanks!
The text was updated successfully, but these errors were encountered: