mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-29 00:10:21 +02:00
Merge remote-tracking branch 'origin/stable-2.0'
This commit is contained in:
commit
12087939ed
3 changed files with 31 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
@c -*-texinfo-*-
|
@c -*-texinfo-*-
|
||||||
@c This is part of the GNU Guile Reference Manual.
|
@c This is part of the GNU Guile Reference Manual.
|
||||||
@c Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
@c Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
|
||||||
@c See the file guile.texi for copying conditions.
|
@c See the file guile.texi for copying conditions.
|
||||||
|
|
||||||
@node Web
|
@node Web
|
||||||
|
@ -1235,6 +1235,14 @@ Return a new response, whose @code{response-port} will continue writing
|
||||||
on @var{port}, perhaps using some transfer encoding.
|
on @var{port}, perhaps using some transfer encoding.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@deffn {Scheme Procedure} response-must-not-include-body? r
|
||||||
|
Some responses, like those with status code 304, are specified as never
|
||||||
|
having bodies. This predicate returns @code{#t} for those responses.
|
||||||
|
|
||||||
|
Note also, though, that responses to @code{HEAD} requests must also not
|
||||||
|
have a body.
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@deffn {Scheme Procedure} read-response-body r
|
@deffn {Scheme Procedure} read-response-body r
|
||||||
Read the response body from @var{r}, as a bytevector. Returns @code{#f}
|
Read the response body from @var{r}, as a bytevector. Returns @code{#f}
|
||||||
if there was no response body.
|
if there was no response body.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
;;; HTTP response objects
|
;;; HTTP response objects
|
||||||
|
|
||||||
;; Copyright (C) 2010, 2011 Free Software Foundation, Inc.
|
;; Copyright (C) 2010, 2011, 2012 Free Software Foundation, Inc.
|
||||||
|
|
||||||
;; This library is free software; you can redistribute it and/or
|
;; This library is free software; you can redistribute it and/or
|
||||||
;; modify it under the terms of the GNU Lesser General Public
|
;; modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -36,6 +36,7 @@
|
||||||
adapt-response-version
|
adapt-response-version
|
||||||
write-response
|
write-response
|
||||||
|
|
||||||
|
response-must-not-include-body?
|
||||||
read-response-body
|
read-response-body
|
||||||
write-response-body
|
write-response-body
|
||||||
|
|
||||||
|
@ -214,6 +215,15 @@ on @var{port}, perhaps using some transfer encoding."
|
||||||
(make-response (response-version r) (response-code r)
|
(make-response (response-version r) (response-code r)
|
||||||
(response-reason-phrase r) (response-headers r) port)))
|
(response-reason-phrase r) (response-headers r) port)))
|
||||||
|
|
||||||
|
(define (response-must-not-include-body? r)
|
||||||
|
"Returns @code{#t} if the response @var{r} is not permitted to have a body.
|
||||||
|
|
||||||
|
This is true for some response types, like those with code 304."
|
||||||
|
;; RFC 2616, section 4.3.
|
||||||
|
(or (<= 100 (response-code r) 199)
|
||||||
|
(= (response-code r) 204)
|
||||||
|
(= (response-code r) 304)))
|
||||||
|
|
||||||
(define (read-response-body r)
|
(define (read-response-body r)
|
||||||
"Reads the response body from @var{r}, as a bytevector. Returns
|
"Reads the response body from @var{r}, as a bytevector. Returns
|
||||||
@code{#f} if there was no response body."
|
@code{#f} if there was no response body."
|
||||||
|
|
|
@ -262,7 +262,11 @@ on the procedure being called at any particular time."
|
||||||
(extend-response response 'content-type
|
(extend-response response 'content-type
|
||||||
`(,@type (charset . ,charset))))
|
`(,@type (charset . ,charset))))
|
||||||
(call-with-encoded-output-string charset body))))
|
(call-with-encoded-output-string charset body))))
|
||||||
((bytevector? body)
|
((not (bytevector? body))
|
||||||
|
(error "unexpected body type"))
|
||||||
|
((response-must-not-include-body? response)
|
||||||
|
(error "response with this status code must not include body" response))
|
||||||
|
(else
|
||||||
;; check length; assert type; add other required fields?
|
;; check length; assert type; add other required fields?
|
||||||
(values (let ((rlen (response-content-length response))
|
(values (let ((rlen (response-content-length response))
|
||||||
(blen (bytevector-length body)))
|
(blen (bytevector-length body)))
|
||||||
|
@ -272,9 +276,12 @@ on the procedure being called at any particular time."
|
||||||
(error "bad content-length" rlen blen)))
|
(error "bad content-length" rlen blen)))
|
||||||
((zero? blen) response)
|
((zero? blen) response)
|
||||||
(else (extend-response response 'content-length blen))))
|
(else (extend-response response 'content-length blen))))
|
||||||
body))
|
(if (eq? (request-method request) 'HEAD)
|
||||||
(else
|
;; Responses to HEAD requests must not include bodies.
|
||||||
(error "unexpected body type"))))
|
;; We could raise an error here, but it seems more
|
||||||
|
;; appropriate to just do something sensible.
|
||||||
|
#f
|
||||||
|
body)))))
|
||||||
|
|
||||||
;; -> response body state
|
;; -> response body state
|
||||||
(define (handle-request handler request body state)
|
(define (handle-request handler request body state)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue