Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 467857 - Treat incorrect headers as empty or absent.
Summary: Treat incorrect headers as empty or absent.
Status: RESOLVED WONTFIX
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: 9.3.0   Edit
Hardware: PC Mac OS X
: P3 blocker with 1 vote (vote)
Target Milestone: 9.3.x   Edit
Assignee: Greg Wilkins CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-21 09:33 EDT by Fedor Ilinykh CLA
Modified: 2015-05-21 10:18 EDT (History)
3 users (show)

See Also:


Attachments
If-Modified-Since:0 is common case with js libraries and AJAX. (39.37 KB, image/png)
2015-05-21 09:52 EDT, Fedor Ilinykh CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Fedor Ilinykh CLA 2015-05-21 09:33:32 EDT
This issue has 7 years history in different situations. Today I faced this one with Chrome+Angular and Jetty again on retrieving static content.
Angular loads html view with incorrect header.

Result of this issue is always the same: Inexperienced devs blame java, jetty and convince non technical management to move to node.js, perl or some other joking technology.

--------------------------
final long date = DateParser.parseDate(val);
        if (date==-1)
            // WHY DO NOT RETURN -1 HERE AND HANDLE PER HEADER BASIC?
            throw new IllegalArgumentException("Cannot convert date: " + val);
        return date;
--------------------------
Here is exception

java.lang.IllegalArgumentException: Cannot convert date: 0
	at org.eclipse.jetty.http.HttpFields.getDateField(HttpFields.java:526)
	at org.eclipse.jetty.server.Request.getDateHeader(Request.java:737)
	at org.eclipse.jetty.servlet.DefaultServlet.passConditionalHeaders(DefaultServlet.java:826)
	at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:527)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:806)
	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:550)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1128)
	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:1062)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:215)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:113)
	at org.eclipse.jetty.server.Server.handle(Server.java:507)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:237)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:240)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:93)
	at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:53)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceRun.produceAndRun(ExecuteProduceRun.java:191)
	at org.eclipse.jetty.util.thread.strategy.ExecuteProduceRun.run(ExecuteProduceRun.java:126)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:641)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:559)
	at java.lang.Thread.run(Thread.java:745)
Comment 1 Fedor Ilinykh CLA 2015-05-21 09:52:51 EDT
Created attachment 253636 [details]
If-Modified-Since:0 is common case with js libraries and AJAX.

If-Modified-Since:0 is common case with js libraries and AJAX.

Jetty must tread such incorrect header as missed.
Comment 2 Greg Wilkins CLA 2015-05-21 10:18:29 EDT
@Fedor,

the problem is that the servlet spec tells us that we have to throw for values that cannot be converted to a date.

Also it is hard to ignore bad values as you may have already revealed the header exists by giving out the header name (and Jetty does not know if you will try to read it as a date or not!).

But if you wish to remove bad headers, then it would be simple to write a handler that could be inserted in the handler tree/chain that checks the format of headers you know are an issue and just removes them or defaults them if they are bad.

Hard to make such a handler totally generic (and there is a cost to use it), but if you wanted to contribute such a handler, we'd consider adding it to jetty.

If you have just some specific headers like If-Modified-Since: 0, you could probably easily setup the rewrite handler to remove them.