From 3475fbb5722fb53a413a89db231ed543cc27c05d Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Mon, 10 Jan 2011 22:09:57 -0800 Subject: (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. --- module/web/request.scm | 48 ++++-------------------------------------------- 1 file changed, 4 insertions(+), 44 deletions(-) (limited to 'module/web/request.scm') diff --git a/module/web/request.scm b/module/web/request.scm index 84bc36e9b..aa807d92a 100644 --- a/module/web/request.scm +++ b/module/web/request.scm @@ -38,11 +38,8 @@ build-request write-request - read-request-body/latin-1 - write-request-body/latin-1 - - read-request-body/bytevector - write-request-body/bytevector + read-request-body + write-request-body ;; General headers ;; @@ -198,44 +195,7 @@ on @var{port}, perhaps using some transfer encoding." (make-request (request-method r) (request-uri r) (request-version r) (request-headers r) (request-meta 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-request-body/latin-1 r) - "Reads the request body from @var{r}, as a string. - -Assumes that the request port has ISO-8859-1 encoding, so that the -number of characters to read is the same as the -@code{request-content-length}. Returns @code{#f} if there was no request -body." - (cond - ((request-content-length r) => - (lambda (nbytes) - (let ((buf (make-string nbytes)) - (port (request-port r))) - (let lp ((i 0)) - (cond - ((< i nbytes) - (let ((c (read-char port))) - (cond - ((eof-object? c) - (bad-request "EOF while reading request 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 server. -;; -(define (write-request-body/latin-1 r body) - "Write @var{body}, a string encodable in ISO-8859-1, to the port -corresponding to the HTTP request @var{r}." - (display body (request-port r))) - -(define (read-request-body/bytevector r) +(define (read-request-body r) "Reads the request body from @var{r}, as a bytevector. Returns @code{#f} if there was no request body." (let ((nbytes (request-content-length r))) @@ -246,7 +206,7 @@ corresponding to the HTTP request @var{r}." (bad-request "EOF while reading request body: ~a bytes of ~a" (bytevector-length bv) nbytes)))))) -(define (write-request-body/bytevector r bv) +(define (write-request-body r bv) "Write @var{body}, a bytevector, to the port corresponding to the HTTP request @var{r}." (put-bytevector (request-port r) bv)) -- cgit v1.2.3