Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 342712 - Date Resolution on HttpFields.putDateField() is lacking
Summary: Date Resolution on HttpFields.putDateField() is lacking
Status: RESOLVED WONTFIX
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X - Carbon (unsup.)
: P3 normal (vote)
Target Milestone: 7.2.x   Edit
Assignee: Greg Wilkins CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-13 09:29 EDT by Nobody CLA
Modified: 2011-05-11 22:15 EDT (History)
1 user (show)

See Also:


Attachments
roundup patch (5.39 KB, patch)
2011-04-13 21:05 EDT, Greg Wilkins CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nobody CLA 2011-04-13 09:29:08 EDT
Build Identifier: 7.3.1.v20110307

If I wish to set the HTTP Response Header "Last-Modified" with the value - 

response.setDateHeader("Last-Modified", 1302623933241)

then Jetty sends this to the browser as the value - Tue, 12 Apr 2011 15:58:53 GMT

This is incorrect as the millisecond component has been disregarded, we have in effect lost 241 milliseconds.

Which means when the browser sends me back the value to Jetty in the next request for the same resource as the "If-Modified-Since" Request Header then Jetty gives me this - 1302623933000.
I then again lookup the last modified date of the resource requested and get 1302623933241 when I compare this against the value request.getDateHeader("If-Modified-Since") (302623933000) then it always appears to me that the resource has been modified and so I cannot return HTTP 304 Not-Modified.

Now I could of course round-up the millisecond component of the timestamp to the nearest second before passing it to Jetty as the Last-Modified header, but somehow it seems to me that Jetty should be responsible for ensuring the round-trip of Date fields in the HTTP Headers. The issue seems to be in Jettys HttpFields.putDateField() in particular the _formatDate(...) function.

I am not sure how other Servlet Containers handle this, and I cannot find that the Servlet spec defines how this long should be mapped to the HTTP Header equivalent.

Reproducible: Always

Steps to Reproduce:
Try round-tripping a date with milliseconds resolution via the HTTP Response Header Last-Modified and then processing the resulting HTTP Request Header If-Modified-Since.
Comment 1 Greg Wilkins CLA 2011-04-13 21:05:09 EDT
Created attachment 193210 [details]
roundup patch

This patch will round up all date handling to the second.
Comment 2 Greg Wilkins CLA 2011-04-13 21:06:44 EDT
I have prepared a patch, but I'm not going to apply it for now.
I am concerned that such a change will break existing code that is written against the current round down logic.

I'll ponder the impacts a bit more before applying.
Comment 3 Greg Wilkins CLA 2011-05-11 22:15:13 EDT
Sorry but I'm not going to change this behaviour - which has been as it is for many years and hundreds of thousands of websites.

While I agree that in hind site, better rounding would have been appropriate, I think it is too late now to change.   The code needed to round down yourself is simple.

Actually, this is a good argument of E-Tags, as they could use the ms timestamp to give better resolution.