Changeset 15054 in project


Ignore:
Timestamp:
06/24/09 19:02:53 (11 years ago)
Author:
sjamaan
Message:

Make set-cookie parser aware of number lists in the Port parameter, and make the cookie-name a symbol

Location:
release/4/intarweb/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/intarweb/trunk/header-parsers.scm

    r15046 r15054  
    375375(define (key/value-subparser str)
    376376  (let ((idx (string-index str #\=)))
    377     (cons (string-take str idx) (string-drop str (add1 idx)))))
     377    (cons (string->symbol (string-take str idx)) (string-drop str (add1 idx)))))
    378378
    379379;; The 'expires' header defined by the Netscape cookie spec contains
     
    381381(define (old-style-cookie? cookie)
    382382  (string-search (regexp "^[^=\"]+=[^;]*;.*expires[[:space:]]*=" #f) cookie))
     383
     384(define (string->number-list str)
     385  (map string->number (string-split str ",")))
    383386
    384387;; We're using http-date-subparser for 'expires' instead of rfc850-subparser
     
    389392  (let ((param-subparsers `((expires . ,http-date-subparser)
    390393                            (max-age . ,string->number)
    391                             (version . ,string->number))))
     394                            (version . ,string->number)
     395                            (port    . ,string->number-list))))
    392396    (lambda (contents)
    393397      (if (old-style-cookie? contents)
  • release/4/intarweb/trunk/tests/run.scm

    r14997 r15054  
    285285    (let* ((headers (test-read-headers "Set-Cookie: foo=\"bar\"")))
    286286      (test "Simple name/value pair"
    287             '("foo" . "bar")
     287            '(foo . "bar")
    288288            (get-value (first (header-contents 'set-cookie headers)))))
    289289    (let ((headers (test-read-headers "Set-Cookie: foo=bar=qux; max-age=10")))
    290290      (test "Cookie with = signs"
    291             '("foo" . "bar=qux")
     291            '(foo . "bar=qux")
    292292            (get-value (first (header-contents 'set-cookie headers)))))
    293293    (let* ((headers (test-read-headers "Set-Cookie: foo=bar; Comment=\"Hi, there!\", qux=mooh\r\nSet-Cookie: mumble=mutter")))
     
    297297                       (first (header-contents 'set-cookie headers))))
    298298      (test "Multiple cookies in one header"
    299             '("qux" . "mooh")
     299            '(qux . "mooh")
    300300            (get-value (second (header-contents 'set-cookie headers))))
    301301      (test "Multiple cookies in multiple headers"
    302             '("mumble" . "mutter")
     302            '(mumble . "mutter")
    303303            (get-value (third (header-contents 'set-cookie headers))))
    304304      (test "Missing \"secure\" value"
     
    306306            (get-param 'secure
    307307                       (third (header-contents 'set-cookie headers)))))
    308     (let* ((headers (test-read-headers "Set-Cookie: foo=; expires=Sunday, 20-Jul-08 15:23:42 GMT; secure; path = / ")))
     308    (let* ((headers (test-read-headers "Set-Cookie: foo=; expires=Sunday, 20-Jul-08 15:23:42 GMT; secure; path = / ; Port=80,8080")))
    309309      (test "Missing value"
    310             '("foo" . "")
     310            '(foo . "")
    311311            (get-value (first (header-contents 'set-cookie headers))))
    312312      (test "Old-style cookie expires value"
     
    322322            "/"
    323323            (get-param 'path
     324                       (first (header-contents 'set-cookie headers))))
     325      (test "Port numbers"
     326            '(80 8080)
     327            (get-param 'port
    324328                       (first (header-contents 'set-cookie headers)))))
    325329    (let* ((headers (test-read-headers "Set-Cookie: foo=; expires=Sun, 20 Jul 2008 15:23:42 GMT; secure; path = / ")))
Note: See TracChangeset for help on using the changeset viewer.