1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-10 14:00:21 +02:00

request and response cleanups

* module/web/request.scm (build-request): Make URI a positional
  argument.

* module/web/response.scm: Remove extend-response.
  (read-response): Fix a docstring.
* module/web/server.scm (extend-response): Include extend-response here,
  but not exported.
This commit is contained in:
Andy Wingo 2011-01-10 22:22:56 -08:00
parent 3475fbb572
commit f944ee8f23
3 changed files with 13 additions and 18 deletions

View file

@ -146,7 +146,7 @@
(if (not (null? headers))
(bad-request "Headers not a list: ~a" headers))))
(define* (build-request #:key (method 'GET) uri (version '(1 . 1))
(define* (build-request uri #:key (method 'GET) (version '(1 . 1))
(headers '()) port (meta '())
(validate-headers? #t))
"Construct an HTTP request object. If @var{validate-headers?} is true,

View file

@ -33,7 +33,6 @@
response-port
read-response
build-response
extend-response
adapt-response-version
write-response
@ -123,20 +122,6 @@ the headers are each run through their respective validators."
(validate-headers headers))))
(make-response version code reason-phrase headers port))
(define (extend-response r k v . additional)
"Extend an HTTP response by setting additional HTTP headers @var{k},
@var{v}. Returns a new HTTP response."
(let ((r (build-response #:version (response-version r)
#:code (response-code r)
#:reason-phrase (%response-reason-phrase r)
#:headers
(assoc-set! (copy-tree (response-headers r))
k v)
#:port (response-port r))))
(if (null? additional)
r
(apply extend-response r additional))))
(define *reason-phrases*
'((100 . "Continue")
(101 . "Switching Protocols")
@ -190,8 +175,7 @@ reason phrase for the response's code."
(code->reason-phrase (response-code response))))
(define (read-response port)
"Read an HTTP response from @var{port}, optionally attaching the given
metadata, @var{meta}.
"Read an HTTP response from @var{port}.
As a side effect, sets the encoding on @var{port} to
ISO-8859-1 (latin-1), so that reading one character reads one byte. See

View file

@ -187,6 +187,17 @@ values."
(lambda (port)
(display str port)))))
(define (extend-response r k v . additional)
(let ((r (build-response #:version (response-version r)
#:code (response-code r)
#:headers
(assoc-set! (copy-tree (response-headers r))
k v)
#:port (response-port r))))
(if (null? additional)
r
(apply extend-response r additional))))
;; -> response body
(define (sanitize-response request response body)
"\"Sanitize\" the given response and body, making them appropriate for