summaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2016-01-07 10:53:57 +0100
committerAndy Wingo <wingo@pobox.com>2016-01-07 10:53:57 +0100
commit6d7c09c8a9900794a855b9c69c57c3d1736506ed (patch)
tree55f149f6b65f8f88c31c071928818856fb80ab48 /module
parent4137c224e24215bd9496dfc2fd084a09383125a2 (diff)
downloadguile-6d7c09c8a9900794a855b9c69c57c3d1736506ed.tar.gz
web: Be less strict when parsing entity tags.
* module/web/http.scm (parse-entity-tag): Be less strict, accepting unquoted strings as well. * test-suite/tests/web-http.test ("response headers"): Add a test for etag parsing.
Diffstat (limited to 'module')
-rw-r--r--module/web/http.scm13
1 files changed, 9 insertions, 4 deletions
diff --git a/module/web/http.scm b/module/web/http.scm
index a157cf021..8a07f6d0d 100644
--- a/module/web/http.scm
+++ b/module/web/http.scm
@@ -1,6 +1,6 @@
;;; HTTP messages
-;; Copyright (C) 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
+;; Copyright (C) 2010, 2011, 2012, 2013, 2014, 2016 Free Software Foundation, Inc.
;; This library is free software; you can redistribute it and/or
;; modify it under the terms of the GNU Lesser General Public
@@ -848,10 +848,15 @@ as an ordered alist."
(display-digits (date-second date) 2 port)
(display " GMT" port)))
+;; Following https://tools.ietf.org/html/rfc7232#section-2.3, an entity
+;; tag should really be a qstring. However there are a number of
+;; servers that emit etags as unquoted strings. Assume that if the
+;; value doesn't start with a quote, it's an unquoted strong etag.
(define (parse-entity-tag val)
- (if (string-prefix? "W/" val)
- (cons (parse-qstring val 2) #f)
- (cons (parse-qstring val) #t)))
+ (cond
+ ((string-prefix? "W/" val) (cons (parse-qstring val 2) #f))
+ ((string-prefix? "\"" val) (cons (parse-qstring val) #t))
+ (else (cons val #t))))
(define (entity-tag? val)
(and (pair? val)