1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

fix up a couple content-length issues in web/server.scm:sanitize-response

* module/web/server.scm (sanitize-response): Allow body to be #f. Don't
  require or insert a content-length if there is no body.
This commit is contained in:
Andy Wingo 2010-11-22 23:58:24 +01:00
parent 015a4aaedb
commit a4342ba826

View file

@ -166,6 +166,8 @@
(cond
((list? response)
(sanitize-response request (build-response #:headers response) body))
((not body)
(values response #vu8()))
((string? body)
(let* ((type (response-content-type response
'("text/plain")))
@ -185,13 +187,14 @@
(sanitize-response request response (call-with-output-string body)))
((bytevector? body)
;; check length; assert type; add other required fields?
(values (let ((len (response-content-length response)))
(if len
(if (= len (bytevector-length body))
response
(error "bad content-length" len (bytevector-length body)))
(extend-response response 'content-length
(bytevector-length body))))
(values (let ((rlen (response-content-length response))
(blen (bytevector-length body)))
(cond
((rlen) (if (= rlen blen)
response
(error "bad content-length" rlen blen)))
((zero? blen) response)
(else (extend-response response 'content-length blen))))
body))
(else
(error "unexpected body type"))))