cookie-error -> error*
svn: r5050
This commit is contained in:
parent
3cedc4c569
commit
8ebd40d0e5
|
@ -60,10 +60,10 @@
|
||||||
(define-struct cookie (name value comment domain max-age path secure version))
|
(define-struct cookie (name value comment domain max-age path secure version))
|
||||||
(define-struct (cookie-error exn:fail) ())
|
(define-struct (cookie-error exn:fail) ())
|
||||||
|
|
||||||
;; cookie-error : string args ... -> raises a cookie-error exception
|
;; error* : string args ... -> raises a cookie-error exception
|
||||||
;; constructs a cookie-error struct from the given error message
|
;; constructs a cookie-error struct from the given error message
|
||||||
;; (added to fix exceptions-must-take-immutable-strings bug)
|
;; (added to fix exceptions-must-take-immutable-strings bug)
|
||||||
(define (cookie-error fmt . args)
|
(define (error* fmt . args)
|
||||||
(make-cookie-error
|
(make-cookie-error
|
||||||
(string->immutable-string (apply format fmt args))
|
(string->immutable-string (apply format fmt args))
|
||||||
(current-continuation-marks)))
|
(current-continuation-marks)))
|
||||||
|
@ -83,7 +83,7 @@
|
||||||
(define (set-cookie name pre-value)
|
(define (set-cookie name pre-value)
|
||||||
(let ([value (to-rfc2109:value pre-value)])
|
(let ([value (to-rfc2109:value pre-value)])
|
||||||
(unless (rfc2068:token? name)
|
(unless (rfc2068:token? name)
|
||||||
(cookie-error "Invalid cookie name: ~a / ~a" name value))
|
(error* "invalid cookie name: ~a / ~a" name value))
|
||||||
(make-cookie name value
|
(make-cookie name value
|
||||||
#f ; comment
|
#f ; comment
|
||||||
#f ; current domain
|
#f ; current domain
|
||||||
|
@ -103,7 +103,7 @@
|
||||||
;; "Set-Cookie: " header, and sent to a client (browser).
|
;; "Set-Cookie: " header, and sent to a client (browser).
|
||||||
(define (print-cookie cookie)
|
(define (print-cookie cookie)
|
||||||
(unless (cookie? cookie)
|
(unless (cookie? cookie)
|
||||||
(cookie-error "Cookie expected, received: ~a" cookie))
|
(error* "cookie expected, received: ~a" cookie))
|
||||||
(string-join
|
(string-join
|
||||||
(filter (lambda (s) (not (string-null? s)))
|
(filter (lambda (s) (not (string-null? s)))
|
||||||
(list (format "~a=~a" (cookie-name cookie) (cookie-value cookie))
|
(list (format "~a=~a" (cookie-name cookie) (cookie-value cookie))
|
||||||
|
@ -118,46 +118,46 @@
|
||||||
(define (cookie:add-comment cookie pre-comment)
|
(define (cookie:add-comment cookie pre-comment)
|
||||||
(let ([comment (to-rfc2109:value pre-comment)])
|
(let ([comment (to-rfc2109:value pre-comment)])
|
||||||
(unless (cookie? cookie)
|
(unless (cookie? cookie)
|
||||||
(cookie-error "Cookie expected, received: ~a" cookie))
|
(error* "cookie expected, received: ~a" cookie))
|
||||||
(set-cookie-comment! cookie comment)
|
(set-cookie-comment! cookie comment)
|
||||||
cookie))
|
cookie))
|
||||||
|
|
||||||
(define (cookie:add-domain cookie domain)
|
(define (cookie:add-domain cookie domain)
|
||||||
(unless (valid-domain? domain)
|
(unless (valid-domain? domain)
|
||||||
(cookie-error "Invalid domain: ~a" domain))
|
(error* "invalid domain: ~a" domain))
|
||||||
(unless (cookie? cookie)
|
(unless (cookie? cookie)
|
||||||
(cookie-error "Cookie expected, received: ~a" cookie))
|
(error* "cookie expected, received: ~a" cookie))
|
||||||
(set-cookie-domain! cookie domain)
|
(set-cookie-domain! cookie domain)
|
||||||
cookie)
|
cookie)
|
||||||
|
|
||||||
(define (cookie:add-max-age cookie seconds)
|
(define (cookie:add-max-age cookie seconds)
|
||||||
(unless (and (integer? seconds) (not (negative? seconds)))
|
(unless (and (integer? seconds) (not (negative? seconds)))
|
||||||
(cookie-error "Invalid Max-Age for cookie: ~a" seconds))
|
(error* "invalid Max-Age for cookie: ~a" seconds))
|
||||||
(unless (cookie? cookie)
|
(unless (cookie? cookie)
|
||||||
(cookie-error "Cookie expected, received: ~a" cookie))
|
(error* "cookie expected, received: ~a" cookie))
|
||||||
(set-cookie-max-age! cookie seconds)
|
(set-cookie-max-age! cookie seconds)
|
||||||
cookie)
|
cookie)
|
||||||
|
|
||||||
(define (cookie:add-path cookie pre-path)
|
(define (cookie:add-path cookie pre-path)
|
||||||
(let ([path (to-rfc2109:value pre-path)])
|
(let ([path (to-rfc2109:value pre-path)])
|
||||||
(unless (cookie? cookie)
|
(unless (cookie? cookie)
|
||||||
(cookie-error "Cookie expected, received: ~a" cookie))
|
(error* "cookie expected, received: ~a" cookie))
|
||||||
(set-cookie-path! cookie path)
|
(set-cookie-path! cookie path)
|
||||||
cookie))
|
cookie))
|
||||||
|
|
||||||
(define (cookie:secure cookie secure?)
|
(define (cookie:secure cookie secure?)
|
||||||
(unless (boolean? secure?)
|
(unless (boolean? secure?)
|
||||||
(cookie-error "Invalid argument (boolean expected), received: ~a" secure?))
|
(error* "invalid argument (boolean expected), received: ~a" secure?))
|
||||||
(unless (cookie? cookie)
|
(unless (cookie? cookie)
|
||||||
(cookie-error "Cookie expected, received: ~a" cookie))
|
(error* "cookie expected, received: ~a" cookie))
|
||||||
(set-cookie-secure! cookie secure?)
|
(set-cookie-secure! cookie secure?)
|
||||||
cookie)
|
cookie)
|
||||||
|
|
||||||
(define (cookie:version cookie version)
|
(define (cookie:version cookie version)
|
||||||
(unless (integer? version)
|
(unless (integer? version)
|
||||||
(cookie-error "Unsupported version: ~a" version))
|
(error* "unsupported version: ~a" version))
|
||||||
(unless (cookie? cookie)
|
(unless (cookie? cookie)
|
||||||
(cookie-error "Cookie expected, received: ~a" cookie))
|
(error* "cookie expected, received: ~a" cookie))
|
||||||
(set-cookie-version! cookie version)
|
(set-cookie-version! cookie version)
|
||||||
cookie)
|
cookie)
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@
|
||||||
(define (to-rfc2109:value s)
|
(define (to-rfc2109:value s)
|
||||||
(cond
|
(cond
|
||||||
[(not (string? s))
|
[(not (string? s))
|
||||||
(cookie-error "Expected string, given: ~e" s)]
|
(error* "expected string, given: ~e" s)]
|
||||||
|
|
||||||
;; for backwards compatibility, just use the given string if it will work
|
;; for backwards compatibility, just use the given string if it will work
|
||||||
[(rfc2068:token? s) s]
|
[(rfc2068:token? s) s]
|
||||||
|
@ -287,7 +287,7 @@
|
||||||
[(rfc2068:quoted-string? (convert-to-quoted s))
|
[(rfc2068:quoted-string? (convert-to-quoted s))
|
||||||
=> (λ (x) x)]
|
=> (λ (x) x)]
|
||||||
[else
|
[else
|
||||||
(cookie-error "Could not convert the given string to an acceptable RFC 2109 value: ~s" s)]))
|
(error* "could not convert the given string to an acceptable RFC 2109 value: ~s" s)]))
|
||||||
|
|
||||||
;;!
|
;;!
|
||||||
;;
|
;;
|
||||||
|
@ -300,7 +300,7 @@
|
||||||
(define cookie-string?
|
(define cookie-string?
|
||||||
(opt-lambda (s (value? #t))
|
(opt-lambda (s (value? #t))
|
||||||
(unless (string? s)
|
(unless (string? s)
|
||||||
(cookie-error "String expected, received: ~a" s))
|
(error* "string expected, received: ~a" s))
|
||||||
(if value?
|
(if value?
|
||||||
(rfc2109:value? s)
|
(rfc2109:value? s)
|
||||||
;; name: token
|
;; name: token
|
||||||
|
|
Loading…
Reference in New Issue
Block a user