Problem/Motivation
Drupal is using gmdate to generate the Last-Modified header in RFC1123 format.
gmdate(DATE_RFC1123, ... Resulting in code matching the following example.
Last-Modified: Tue, 12 Feb 2013 14:35:43 +0000
This is a valid rfc1123 date, however rfc2616 specifies a specific subset of RFC1123 for header dates which this does not conform to. Specifically, dates must be formated using "GMT" instead of "+0000".
Some software can't handle the none standard syntax with at least squid-3.1.10 printing messages like:
cannot parse hdr field: 'Last-Modified: Tue, 12 Feb 2013 14:35:43 +0000'
and refusing to cache the page.
Proposed resolution
Replacing DATE_RFC1123 dates in headers with a custom, correctly formatted format string.
Remaining tasks
User interface changes
API changes
Original report by @0x534B41
Drupal is using gmdate to generate the Last-Modified header in RFC1123 format.
gmdate(DATE_RFC1123, ...
At least with php-5.3.3 the generated header is like the following:
Last-Modified: Tue, 12 Feb 2013 14:35:43 +0000
Note the "+0000" part. This seems to be valid by rfc1123 but all the examples in rfc2616 use "GMT" instead of "+0000".
And it looks like some HTTP software can't handle the +0000 syntax. At least squid-3.1.10 is printing messages like:
cannot parse hdr field: 'Last-Modified: Tue, 12 Feb 2013 14:35:43 +0000'
and refusing to cache the page.
Other HTTP software (browsers, caches) may or may not have this issue (haven't tested yet).
Replacing DATE_RFC1123 with DATE_RFC850 in gmdate function call "resolves" the issue with squid.
| Comment | File | Size | Author |
|---|---|---|---|
| #49 | after.png | 4.55 KB | dcam |
| #46 | d_7-1918820-46.patch | 3.68 KB | girishmuraly |
| #42 | 1918820-42.patch | 7.11 KB | neclimdul |
| #21 | Selection_518.png | 100.79 KB | elijah lynn |
| #11 | 1918820-11.patch | 4.75 KB | adammalone |
Comments
Comment #1
damien tournoud commentedHm. HTTP/1.1 does specify the date format, and it's pretty rigid. It is not RFC1123, but only a subset that hardcodes "GMT" as the timezone identifier.
RFC850 being completely obsolete, let's not go back to that.
The current definition of DATE_RFC1132 is
"D, d M Y H:i:s O". Replacing it by"D, d M Y H:i:s T"should do the trick.Comment #2
damien tournoud commentedThat, or
gm_date('D, d M Y H:i:s').' GMT', which is what Symfony currently does.Comment #3
damien tournoud commentedOk, this is present in Drupal 8 also, so it needs to be fixed there first.
Comment #4
0x534B41 commentedI think gm_date('D, d M Y H:i:s').' GMT' will do well.
I think we should also consider the possibility that people depend on this bug (i.e. it gets fixed and breaks people's stuff).
Will 8.x-dev be adequate testing for this (before it gets into Drupal7)?
Comment #5
neclimdulrelevant 11 year old post on php.net http://php.net/gmdate#25031
Comment #6
elijah lynn@0x534B41 I think it would be a great test bed with D8 to test this out and then hopefully backport to D7!
Comment #7
elijah lynnREDbot complains about Drupal.org too.
https://redbot.org/?uri=https%3A%2F%2Fdrupal.org
Comment #8
pwolanin commentedFirst pass for 8.x
Comment #9
adammaloneAdded in a the other occurrences of RFC1123. At least, I assume all of them should be replaced
Comment #11
adammaloneOuch, that was embarrassing. Let's try that again with the brackets in the right places.
Comment #12
adammaloneComment #13
neclimdulChanging all the dates is probably appropriate. Relevant documentation from the RFC in the summary.
Comment #14
neclimdulHelper constant on DateTimePlus seems a handy way to handle this in D8 so it is easier to reuse this. While making the modifications I noticed a couple calls to RFC822 dates. These are, for the purposes of this issue, the same as RFC1123 so likely wrong as well.
Comment #15
neclimdulWoops, there was a stray character in bootstrap.inc
Comment #18
neclimdulNow I'm embarrassed. Missing use statement.
Comment #20
neclimdulSorry for the noise guys
Comment #21
elijah lynnW00T! Works, Redbot test passed!
Comment #22
elijah lynnComment #23
pwolanin commentedThat's more elegant, thanks necimdul.
Comment #24
elijah lynnMy only concern is the naming of this constant. It seems like it should be more specific. Like DATE_RFC2616.
Thoughts?
Comment #25
neclimdulI named it similar to the php.net date constants http://us3.php.net/manual/en/class.datetime.php#datetime.constants.types.
Comment #27
neclimdulre-roll. going to be bold and just push this back to rtbc.
Comment #29
neclimdulNamespace conflict. No changes still.
Comment #30
neclimdulConsidering updating the RFC. http://tools.ietf.org/html/rfc7231#section-7.1.1.1 Format is the same but the documentation is more up to date. Thoughts?
Comment #31
liviepm commented8: 1918820-8.patch queued for re-testing.
Comment #32
liviepm commented11: 1918820-11.patch queued for re-testing.
Comment #33
chx commentedYes @ 30.
Comment #34
neclimdulBeen a bug so long a new RFC came out describing it. Time to get this committed ;).
Comment #35
chx commentedTotes.
Comment #38
neclimdulautomated re-roll.
Comment #40
neclimdulalmost automated re-roll. Namespace conflict in toolbar.module. Still no changes.
Comment #41
alexpottPatch in #40 is for another issue :)
Comment #42
neclimdulBah, lazy patch naming bit me clearly. Well here's a re-roll so we're sure its up to date.
Comment #43
alexpottCommitted 5dd3776 and pushed to 8.x. Thanks!
Comment #45
pwolanin commentedComment #46
girishmuraly commentedHope to set the ball rolling on the D7 backport.
Comment #47
girishmuraly commentedComment #48
girishmuraly commentedCould someone please test this and mark RTBC?
Comment #49
dcam commented#46 looks good to me. After applying, the Last Modified header is in the correct format.
I checked for other uses of DATE_RFC1123 and couldn't find any others in core that aren't fixed by the patch. I did note, however, that the admin_menu module outputs a header using DATE_RFC1123. So maybe this will need a change record so contrib maintainers will be aware of the change. I don't know if that's appropriate or necessary.
Anyway, #46 seems RTBC to me.
Comment #50
David_Rothstein commentedCommitted to 7.x - thanks!
Looks like this also makes Drupal more internally consistent, since the "Expires" header was already in this format.
As for a change notice, I'm not sure it necessarily needs one given that this is a relatively minor change - though it certainly wouldn't hurt and it would be a way to inform contrib modules about this. For now, I did put it in CHANGELOG.txt and the release notes.
Comment #53
klausiThis broke Varnish page caching, see #2381839: Changed date format for Last-Modified header breaks caching for Varnish/Nginx configs.