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.

Comments

damien tournoud’s picture

Hm. 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.

damien tournoud’s picture

That, or gm_date('D, d M Y H:i:s').' GMT', which is what Symfony currently does.

damien tournoud’s picture

Version: 7.19 » 8.x-dev

Ok, this is present in Drupal 8 also, so it needs to be fixed there first.

0x534B41’s picture

I 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)?

neclimdul’s picture

relevant 11 year old post on php.net http://php.net/gmdate#25031

elijah lynn’s picture

Issue summary: View changes

@0x534B41 I think it would be a great test bed with D8 to test this out and then hopefully backport to D7!

elijah lynn’s picture

REDbot complains about Drupal.org too.
https://redbot.org/?uri=https%3A%2F%2Fdrupal.org

The Last-Modified header's value isn't a valid date.

HTTP/1.1 200 OK
    Server: nginx/1.6.0
    Date: Wed, 28 May 2014 19:25:39 GMT
    Content-Type: text/html; charset=utf-8
    Transfer-Encoding: chunked
    Connection: keep-alive
    Vary: Accept-Encoding
    X-Drupal-Cache: HIT
    Content-Language: en
    X-Generator: Drupal 7 (http://drupal.org)
    Link: <https://drupal.org/>;
        rel="shortlink",<https://drupal.org/>; rel="canonical"
    Cache-Control: public, max-age=0
    Last-Modified: Wed, 28 May 2014 19:18:17 +0000
    Expires: Sun, 19 Nov 1978 05:00:00 GMT
    Vary: Cookie,Accept-Encoding
    X-Varnish: 1611016738
    Age: 0
    Via: 1.1 varnish
    X-Cache-Svr: www6.drupal.org
    X-Cache: MISS
    Front-End-Https: on
    Content-Encoding: gzip
pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new1.49 KB

First pass for 8.x

adammalone’s picture

StatusFileSize
new4.86 KB

Added in a the other occurrences of RFC1123. At least, I assume all of them should be replaced

Status: Needs review » Needs work

The last submitted patch, 9: 1918820-9.patch, failed testing.

adammalone’s picture

StatusFileSize
new4.75 KB

Ouch, that was embarrassing. Let's try that again with the brackets in the right places.

adammalone’s picture

Status: Needs work » Needs review
neclimdul’s picture

Title: HTTP 'Last-Modified' header format » HTTP header datea formats
Issue summary: View changes

Changing all the dates is probably appropriate. Relevant documentation from the RFC in the summary.

a fixed-length subset of that defined by RFC 1123 [8] (an update to RFC 822 [9]) ... representing HTTP-date values in header fields.

neclimdul’s picture

StatusFileSize
new7.08 KB
new7.15 KB

Helper 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.

neclimdul’s picture

StatusFileSize
new6.51 KB

Woops, there was a stray character in bootstrap.inc

The last submitted patch, 14: 1918820-14.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 15: 1918820-15.patch, failed testing.

neclimdul’s picture

Status: Needs work » Needs review
StatusFileSize
new6.83 KB

Now I'm embarrassed. Missing use statement.

Status: Needs review » Needs work

The last submitted patch, 18: 1918820-18.patch, failed testing.

neclimdul’s picture

Title: HTTP header datea formats » HTTP header date formats
Status: Needs work » Needs review
StatusFileSize
new6.75 KB

Sorry for the noise guys

elijah lynn’s picture

StatusFileSize
new100.79 KB

W00T! Works, Redbot test passed!

elijah lynn’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs backport to D7
pwolanin’s picture

That's more elegant, thanks necimdul.

elijah lynn’s picture

+++ b/core/lib/Drupal/Component/Datetime/DateTimePlus.php
@@ -31,6 +31,13 @@ class DateTimePlus extends \DateTime {
+   * A RFC2616 compliant subset of RFC1123.
+   *
+   * Example: Sun, 06 Nov 1994 08:49:37 GMT
+   */
+  const RFC2616 = 'D, d M Y H:i:s \G\M\T';
+
+  /**

My only concern is the naming of this constant. It seems like it should be more specific. Like DATE_RFC2616.

Thoughts?

neclimdul’s picture

I named it similar to the php.net date constants http://us3.php.net/manual/en/class.datetime.php#datetime.constants.types.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: 1918820-20.patch, failed testing.

neclimdul’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new6.76 KB

re-roll. going to be bold and just push this back to rtbc.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 1918820-27.patch, failed testing.

neclimdul’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new7 KB

Namespace conflict. No changes still.

neclimdul’s picture

Considering 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?

liviepm’s picture

8: 1918820-8.patch queued for re-testing.

liviepm’s picture

11: 1918820-11.patch queued for re-testing.

chx’s picture

Status: Reviewed & tested by the community » Needs work

Yes @ 30.

neclimdul’s picture

Status: Needs work » Needs review
StatusFileSize
new7.05 KB
new5.47 KB

Been a bug so long a new RFC came out describing it. Time to get this committed ;).

chx’s picture

Status: Needs review » Reviewed & tested by the community

Totes.

The last submitted patch, 29: 1918820-29.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 34: 1918820-34.patch, failed testing.

neclimdul’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new7.05 KB

automated re-roll.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 38: 1918820-38.patch, failed testing.

neclimdul’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new7.86 KB

almost automated re-roll. Namespace conflict in toolbar.module. Still no changes.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Patch in #40 is for another issue :)

neclimdul’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new7.11 KB

Bah, lazy patch naming bit me clearly. Well here's a re-roll so we're sure its up to date.

alexpott’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Committed 5dd3776 and pushed to 8.x. Thanks!

  • alexpott committed 5dd3776 on 8.x
    Issue #1918820 by neclimdul, typhonius, pwolanin | 0x534B41: Fixed HTTP...
pwolanin’s picture

Version: 8.x-dev » 7.x-dev
girishmuraly’s picture

StatusFileSize
new3.68 KB

Hope to set the ball rolling on the D7 backport.

girishmuraly’s picture

Status: Patch (to be ported) » Needs review
girishmuraly’s picture

Could someone please test this and mark RTBC?

dcam’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new4.55 KB

#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.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +7.33 release notes

Committed 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.

  • David_Rothstein committed df8de73 on 7.x
    Issue #1918820 by neclimdul, typhonius, girishmuraly, pwolanin |...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

klausi’s picture