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

Regression: If-Modified-Since value of zero not accepted anymore [SPR-14144] #18716

Closed
spring-issuemaster opened this issue Apr 11, 2016 · 4 comments
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Apr 11, 2016

Dan Costelloe opened SPR-14144 and commented

Greetings,

I discovered an issue recently after migrating a spring-boot application from 1.2.7.RELEASE to 1.3.3.RELEASE. After upgrading, the underlying spring-web module is spring-web:4.2.5.RELEASE. Prior to the upgrade, the version was spring-web:4.1.8.RELEASE.

Client requests had previously been sending the header "If-Modified-Since: 0" wihout errors

After the upgrade, same requests cause 500 server error and the following stack-trace:

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Cannot parse date value "0" for "If-Modified-Since" header
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:980)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:595)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:191)
	at org.eclipse.jetty.server.Dispatcher.error(Dispatcher.java:77)
	at org.eclipse.jetty.server.handler.ErrorHandler.handle(ErrorHandler.java:92)
	at com.groupon.lex.service.jetty.CustomErrorHandler.handle(CustomErrorHandler.java:70)
	at org.eclipse.jetty.server.Response.sendError(Response.java:597)
	at org.eclipse.jetty.server.Response.sendError(Response.java:544)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:647)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.handler.RequestLogHandler.handle(RequestLogHandler.java:95)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
	at org.eclipse.jetty.server.Server.handle(Server.java:499)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
	at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Cannot parse date value "0" for "If-Modified-Since" header
	at org.springframework.http.HttpHeaders.getFirstDate(HttpHeaders.java:970)
	at org.springframework.http.HttpHeaders.getIfModifiedSince(HttpHeaders.java:805)
	at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.isResourceNotModified(HttpEntityMethodProcessor.java:191)
	at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:173)
	at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:80)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:126)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:817)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:731)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:968)
	... 39 common frames omitted

It seems that a question about this issue has also been asked on StackOverflow:

http://stackoverflow.com/questions/33806370/spring-boot-throwing-exception-on-invalid-if-modified-since-value

I'm currently working around the issue using a filter which removes the problematic header, however it looks (to my eyes at least) like a fairly straightforward fix could be implemented in HttpHeaders.java

I've forked the codebase and will submit a PR once JIRA gives me a ticket ID.


Affects: 4.2.5

Reference URL: http://stackoverflow.com/questions/33806370/spring-boot-throwing-exception-on-invalid-if-modified-since-value

Referenced from: commits e0642c7, 448621a

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 11, 2016

Dan Costelloe commented

PR submitted #1029

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 11, 2016

Juergen Hoeller commented

Actually, we should be leniently ignoring invalid header values for all concrete accessors. I'd rather keep the generic getFirstDate call restrictive there, with an IllegalArgumentException raised for invalid values... but getIfModifiedSince and getLastModified should be leniently returning -1 in such cases, just like getExpires does already.

As a consequence, I've taken a slightly broader approach than just ignoring "0" specifically. Thanks for the pull request in any case, that's very helpful input!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 11, 2016

Dan Costelloe commented

Yes, I see that now. I'm happy to follow-up with that in the PR if it helps?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Apr 11, 2016

Juergen Hoeller commented

No worries, I've got this about to be pushed already. Would be great if you could give it a try against the upcoming 4.3.0.BUILD-SNAPSHOT or 4.2.6.BUILD-SNAPSHOT...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.