#| -*-Scheme-*-
-$Id: http-syntax.scm,v 1.4 2008/09/21 22:20:14 cph Exp $
+$Id: http-syntax.scm,v 1.5 2008/09/21 23:20:00 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
(begin
(guarantee-http-text value 'MAKE-HTTP-HEADER)
(%make-header name value
- (%call-parser (hvdefn-parser defn) value))))
+ (%call-parser (hvdefn-parser defn) value #t))))
(begin
(guarantee-http-text value 'MAKE-HTTP-HEADER)
(%make-header name value (%unparsed-value))))))
value
(let ((defn (header-value-defn name)))
(if defn
- (%call-parser (hvdefn-parser defn) value)
+ (%call-parser (hvdefn-parser defn) value #f)
(%unparsed-value)))))))))
-(define (%call-parser parser value)
+(define (%call-parser parser value error?)
(parser value
(lambda (parsed-value)
parsed-value)
(lambda ()
- (warn "Ill-formed HTTP header value:" value)
+ (if error?
+ (error "Ill-formed HTTP header value:" value)
+ (warn "Ill-formed HTTP header value:" value))
(%unparsed-value))))
(define (%unparsed-value)
(define lp:token
(list-parser (map intern lp:token-string)))
-(define lp:token-cs
- (list-parser (map string->symbol lp:token-string)))
-
(define lp:token-string
(list-parser (map token-token->string (match-if token-token?))))
(and (pair? object)
(token*? object)))
-(define lp:token-cs*
- (lp:comma-list 0 lp:token-cs))
-
(define (token*? object)
(list-of-type? object http-token?))
(or (hostport? received-by)
(http-token? received-by)))))
(lambda (value port)
- (let ((received-protocol (car value)))
- (if (car received-protocol)
- (begin
- (write-http-token (car received-protocol) port)
- (write-char #\/ port)))
- (write-http-token (cdr received-protocol) port))
- (let ((received-by (cdr value)))
- (if (hostport? received-by)
- (write-hostport received-by port)
- (write-http-token received-by port)))))
+ (write-comma-list (lambda (elt port)
+ (let ((received-protocol (car elt)))
+ (if (car received-protocol)
+ (begin
+ (write-http-token (car received-protocol) port)
+ (write-char #\/ port)))
+ (write-http-token (cdr received-protocol) port))
+ (let ((received-by (cdr elt)))
+ (if (hostport? received-by)
+ (write-hostport received-by port)
+ (write-http-token received-by port))))
+ value
+ port)))
\f
(define-header "Warning"
(tokenized-parser
(or (not dt)
(decoded-time? dt)))))
(lambda (value port)
- (receive (code agent text date) (vector->values value)
- (write-string (string-pad-left (number->string code) 3 #\0) port)
- (write-char #\space port)
- (if (hostport? agent)
- (write-hostport agent port)
- (write-http-token agent port))
- (write-char #\space port)
- (write-quoted-string text port)
- (if date
- (begin
- (write-char #\space port)
- (write-quoted-string (call-with-output-string
- (lambda (port)
- (write-http-date date port)))
- port))))))
+ (write-comma-list
+ (lambda (elt port)
+ (receive (code agent text date) (vector->values value)
+ (write-string (string-pad-left (number->string code) 3 #\0) port)
+ (write-char #\space port)
+ (if (hostport? agent)
+ (write-hostport agent port)
+ (write-http-token agent port))
+ (write-char #\space port)
+ (write-quoted-string text port)
+ (if date
+ (begin
+ (write-char #\space port)
+ (write-quoted-string (call-with-output-string
+ (lambda (port)
+ (write-http-date date port)))
+ port)))))
+ value
+ port)))
\f
;;;; Request headers
http-token?
accept-params?))
(lambda (value port)
- (write-http-token (car value) port)
- (write-parameter* (cdr value) port)))
+ (write-comma-list (lambda (elt port)
+ (write-http-token (car elt) port)
+ (write-parameter* (cdr elt) port))
+ value
+ port)))
(define-header "User-Agent"
(tokenized-parser lp:product/comment-list)
(alt (encapsulate (lambda (none) none '())
(qualify (token= 'NONE) lp:token))
lp:token+)))
- (lambda (value)
- (list+-of-type? value http-token?))
+ token*?
(lambda (value port)
(if (null? value)
(write-http-token 'NONE port)
;;;; Entity headers
(define-header "Allow"
- (tokenized-parser lp:token-cs*)
+ (tokenized-parser
+ (lp:comma-list 0
+ (list-parser
+ (map string->symbol
+ lp:token-string))))
token*?
write-token*)