unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Daniel Hartwig <mandyke@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-user@gnu.org, 10147@debbugs.gnu.org
Subject: bug#10147: HTTP "Expires" header should handle non-date values
Date: Tue, 27 Dec 2011 23:49:00 +0800	[thread overview]
Message-ID: <CAN3veRfgg+dDzjMy1L8xaAcaZ82dAuFM1dnNpGbzq-5ckoVsAA__24063.2126959555$1325000975$gmane$org@mail.gmail.com> (raw)
In-Reply-To: <87hb0srdgz.fsf@pobox.com>

[-- Attachment #1: Type: text/plain, Size: 1672 bytes --]

On 22 December 2011 20:35, Andy Wingo <wingo@pobox.com> wrote:
>> Not sure precisely what you mean here.  Is it something like:
>>
>> (or (false-if-exception (parse-date str))
>>     (and (memq str '("0" "-1")) str)
>>     date-in-the-past)
>
> More like:
>
>  (if (member str '("0" "-1"))
>      date-in-the-past
>      (parse-date str))
>
> Then we can wait and see -- if only these two values are out there, then
> we are good, and we keep the "validating" characteristic of our date
> parser.  Otherwise we can fall back to the false-if-exception dance if
> someone submits a bug report.

A rough check against ~2600 sites scraped from dmoz.org shows only a
handful with other values.  These two:

"Mon, 12 Jul 1996 1:00:00 GMT"
                  ^ misses leading `0'
"Thu, 01 Jan 1970 00:00:00 +0000"
                           ^ should be `GMT'

The second (use of `+0000') was also encountered amongst other
date-valued headers in ~1% of pages sampled.  There might be a case
here for relaxing `parse-date' as I don't think these should be
handled specifically for "Expires" headers.

There were three more like:

"{ts '2011-12-27 08:12:22'}"

which only appeared for "Expires" headers.  They look something like
server directives which should have been transformed to legit
expiration dates but haven't been, due to misconfiguration.  In this
case I'd rather throw an error than parse it (wrongly) to
date-in-the-past.

Given those points, I have attached a patch implementing the suggested
handling for "Expires" and will take a look at perhaps relaxing
parse-date (and others).  Anyone have ideas on that?


Daniel

[-- Attachment #2: 0001-permit-non-date-values-for-Expires-header.patch --]
[-- Type: text/x-patch, Size: 889 bytes --]

From 8b7eda0bd7b03467f6eef0ce6c99dedf8fd3ac0c Mon Sep 17 00:00:00 2001
From: Daniel Hartwig <mandyke@gmail.com>
Date: Tue, 27 Dec 2011 22:24:28 +0800
Subject: [PATCH] permit non-date values for Expires header

* module/web/http.scm ("Expires"): Permit (some) non-date values.
---
 module/web/http.scm |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/module/web/http.scm b/module/web/http.scm
index afe70a7..9bb4449 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -1506,7 +1506,15 @@ phrase\"."
 
 ;; Expires = HTTP-date
 ;;
-(declare-date-header! "Expires")
+(define *date-in-the-past* (parse-date "Thu, 01 Jan 1970 00:00:00 GMT"))
+
+(declare-header! "Expires"
+  (lambda (str)
+    (if (member str '("0" "-1"))
+        *date-in-the-past*
+        (parse-date str)))
+  date?
+  write-date)
 
 ;; Last-Modified = HTTP-date
 ;;
-- 
1.7.5.4


  reply	other threads:[~2011-12-27 15:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-27 10:39 HTTP "Expires" header should handle non-date values Daniel Hartwig
2011-12-22  2:51 ` bug#10147: " Andy Wingo
2011-12-22  4:28   ` Daniel Hartwig
2011-12-22 12:35     ` Andy Wingo
2011-12-27 15:49       ` Daniel Hartwig [this message]
     [not found]       ` <CAN3veRfgg+dDzjMy1L8xaAcaZ82dAuFM1dnNpGbzq-5ckoVsAA@mail.gmail.com>
2012-01-09 22:36         ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN3veRfgg+dDzjMy1L8xaAcaZ82dAuFM1dnNpGbzq-5ckoVsAA__24063.2126959555$1325000975$gmane$org@mail.gmail.com' \
    --to=mandyke@gmail.com \
    --cc=10147@debbugs.gnu.org \
    --cc=guile-user@gnu.org \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).