read-response-body always returns bytevector or #f
authorAndy Wingo <wingo@pobox.com>
Fri, 11 Jan 2013 10:30:29 +0000 (11:30 +0100)
committerAndy Wingo <wingo@pobox.com>
Fri, 11 Jan 2013 14:15:43 +0000 (15:15 +0100)
* module/web/response.scm (read-response-body): Fix to always return
  either a bytevector or #f.  Previously, reading a 0-length body could
  return the EOF object.

module/web/response.scm

index 5ca7274..7e14f4d 100644 (file)
@@ -1,6 +1,6 @@
 ;;; HTTP response objects
 
-;; Copyright (C)  2010, 2011, 2012 Free Software Foundation, Inc.
+;; Copyright (C)  2010, 2011, 2012, 2013 Free Software Foundation, Inc.
 
 ;; This library is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU Lesser General Public
@@ -294,7 +294,13 @@ response port."
 (define (read-response-body r)
   "Reads the response body from R, as a bytevector.  Returns
 â€˜#f’ if there was no response body."
-  (and=> (response-body-port r #:decode? #f) get-bytevector-all))
+  (let ((body (and=> (response-body-port r #:decode? #f)
+                     get-bytevector-all)))
+    ;; Reading a body of length 0 will result in get-bytevector-all
+    ;; returning the EOF object.
+    (if (eof-object? body)
+        #vu8()
+        body)))
 
 (define (write-response-body r bv)
   "Write BV, a bytevector, to the port corresponding to the HTTP