summaryrefslogtreecommitdiff
path: root/module/web/response.scm
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-01-10 22:09:57 -0800
committerAndy Wingo <wingo@pobox.com>2011-01-10 22:44:36 -0800
commit3475fbb5722fb53a413a89db231ed543cc27c05d (patch)
tree33e94b9a1c3efc9efaa764c5029d0cc2004a2789 /module/web/response.scm
parentff8339db69811ef9c736379b9127e60a3ff74b05 (diff)
downloadguile-3475fbb5722fb53a413a89db231ed543cc27c05d.tar.gz
(web response) and (web request): bodies are bytevectors
* module/web/request.scm (read-request-body, write-request-body): Rename from read-request-body/bytevector and write-request-body/bytevector. Remove the /latin-1 variants, as they were unused and a bad idea. * module/web/response.scm (read-response-body, write-response-body): Likewise. * module/web/server/http.scm (http-read, http-write): Adapt to request/response change. * test-suite/tests/web-request.test: * test-suite/tests/web-response.test: Update tests.
Diffstat (limited to 'module/web/response.scm')
-rw-r--r--module/web/response.scm48
1 files changed, 4 insertions, 44 deletions
diff --git a/module/web/response.scm b/module/web/response.scm
index f8a87a256..c87f881a0 100644
--- a/module/web/response.scm
+++ b/module/web/response.scm
@@ -37,11 +37,8 @@
adapt-response-version
write-response
- read-response-body/latin-1
- write-response-body/latin-1
-
- read-response-body/bytevector
- write-response-body/bytevector
+ read-response-body
+ write-response-body
;; General headers
;;
@@ -233,44 +230,7 @@ on @var{port}, perhaps using some transfer encoding."
(make-response (response-version r) (response-code r)
(response-reason-phrase r) (response-headers r) port)))
-;; Probably not what you want to use "in production". Relies on one byte
-;; per char because we are in latin-1 encoding.
-;;
-(define (read-response-body/latin-1 r)
- "Reads the response body from @var{r}, as a string.
-
-Assumes that the response port has ISO-8859-1 encoding, so that the
-number of characters to read is the same as the
-@code{response-content-length}. Returns @code{#f} if there was no
-response body."
- (cond
- ((response-content-length r) =>
- (lambda (nbytes)
- (let ((buf (make-string nbytes))
- (port (response-port r)))
- (let lp ((i 0))
- (cond
- ((< i nbytes)
- (let ((c (read-char port)))
- (cond
- ((eof-object? c)
- (bad-response "EOF while reading response body: ~a bytes of ~a"
- i nbytes))
- (else
- (string-set! buf i c)
- (lp (1+ i))))))
- (else buf))))))
- (else #f)))
-
-;; Likewise, assumes that body can be written in the latin-1 encoding,
-;; and that the latin-1 encoding is what is expected by the client.
-;;
-(define (write-response-body/latin-1 r body)
- "Write @var{body}, a string encodable in ISO-8859-1, to the port
-corresponding to the HTTP response @var{r}."
- (display body (response-port r)))
-
-(define (read-response-body/bytevector r)
+(define (read-response-body r)
"Reads the response body from @var{r}, as a bytevector. Returns
@code{#f} if there was no response body."
(let ((nbytes (response-content-length r)))
@@ -281,7 +241,7 @@ corresponding to the HTTP response @var{r}."
(bad-response "EOF while reading response body: ~a bytes of ~a"
(bytevector-length bv) nbytes))))))
-(define (write-response-body/bytevector r bv)
+(define (write-response-body r bv)
"Write @var{body}, a bytevector, to the port corresponding to the HTTP
response @var{r}."
(put-bytevector (response-port r) bv))