mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-18 01:42:24 +02:00
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.
This commit is contained in:
parent
5c8b3be820
commit
c5dac3595f
2 changed files with 9 additions and 3 deletions
|
@ -848,10 +848,15 @@ as an ordered alist."
|
||||||
(display-digits (date-second date) 2 port)
|
(display-digits (date-second date) 2 port)
|
||||||
(display " GMT" 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)
|
(define (parse-entity-tag val)
|
||||||
(if (string-prefix? "W/" val)
|
(cond
|
||||||
(cons (parse-qstring val 2) #f)
|
((string-prefix? "W/" val) (cons (parse-qstring val 2) #f))
|
||||||
(cons (parse-qstring val) #t)))
|
((string-prefix? "\"" val) (cons (parse-qstring val) #t))
|
||||||
|
(else (cons val #t))))
|
||||||
|
|
||||||
(define (entity-tag? val)
|
(define (entity-tag? val)
|
||||||
(and (pair? val)
|
(and (pair? val)
|
||||||
|
|
|
@ -353,6 +353,7 @@
|
||||||
(pass-if-parse age "30" 30)
|
(pass-if-parse age "30" 30)
|
||||||
(pass-if-parse etag "\"foo\"" '("foo" . #t))
|
(pass-if-parse etag "\"foo\"" '("foo" . #t))
|
||||||
(pass-if-parse etag "W/\"foo\"" '("foo" . #f))
|
(pass-if-parse etag "W/\"foo\"" '("foo" . #f))
|
||||||
|
(pass-if-parse etag "foo" '("foo" . #t))
|
||||||
(pass-if-parse location "http://other-place"
|
(pass-if-parse location "http://other-place"
|
||||||
(build-uri 'http #:host "other-place"))
|
(build-uri 'http #:host "other-place"))
|
||||||
(pass-if-parse proxy-authenticate "Basic realm=\"guile\""
|
(pass-if-parse proxy-authenticate "Basic realm=\"guile\""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue