1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-24 12:20:20 +02:00

(web http): keys are always symbols

* module/web/http.scm (parse-media-type): Parse media types as symbols.
  (parse-key-value-list, parse-param-component, parse-param-list):
  Change kons to val-parser. Always parse keys as symbols, and always
  either cons, if there is a val, or just have the key, if there is no
  val.  Easier to explain and just as correct.
  (declare-param-list-header!, declare-key-value-list-header!): Adapt to
  key-list and param-list kons change.
  ("Cache-Control", "Pragma", "Transfer-Encoding", "Accept", "Expect")
  ("TE"): Likewise, adapt.
  ("Content-Type"): Param keys are symbols.
This commit is contained in:
Andy Wingo 2011-01-08 20:50:46 -08:00
parent 32de1aa783
commit 0acc595b94
7 changed files with 83 additions and 100 deletions

View file

@ -1,6 +1,6 @@
;;; Web server
;; Copyright (C) 2010 Free Software Foundation, Inc.
;; Copyright (C) 2010, 2011 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
@ -219,27 +219,27 @@ on the procedure being called at any particular time."
(values response #vu8()))
((string? body)
(let* ((type (response-content-type response
'("text/plain")))
(declared-charset (assoc-ref (cdr type) "charset"))
'(text/plain)))
(declared-charset (assq-ref (cdr type) 'charset))
(charset (or declared-charset "utf-8")))
(sanitize-response
request
(if declared-charset
response
(extend-response response 'content-type
`(,@type ("charset" . ,charset))))
`(,@type (charset . ,charset))))
(encode-string body charset))))
((procedure? body)
(let* ((type (response-content-type response
'("text/plain")))
(declared-charset (assoc-ref (cdr type) "charset"))
'(text/plain)))
(declared-charset (assq-ref (cdr type) 'charset))
(charset (or declared-charset "utf-8")))
(sanitize-response
request
(if declared-charset
response
(extend-response response 'content-type
`(,@type ("charset" . ,charset))))
`(,@type (charset . ,charset))))
(call-with-encoded-output-string charset body))))
((bytevector? body)
;; check length; assert type; add other required fields?
@ -370,7 +370,7 @@ For example, here is a simple \"Hello, World!\" server:
@example
(define (handler request body)
(values '((content-type . (\"text/plain\")))
(values '((content-type . (text/plain)))
\"Hello, World!\"))
(run-server handler)
@end example