[bknr-cvs] edi changed trunk/thirdparty/drakma/request.lisp

BKNR Commits bknr at bknr.net
Wed Aug 27 10:13:01 UTC 2008


Revision: 3742
Author: edi
URL: http://bknr.net/trac/changeset/3742

Read content as binary if length is known
Also, read trailers from the right stream

U   trunk/thirdparty/drakma/request.lisp

Modified: trunk/thirdparty/drakma/request.lisp
===================================================================
--- trunk/thirdparty/drakma/request.lisp	2008-08-27 02:40:48 UTC (rev 3741)
+++ trunk/thirdparty/drakma/request.lisp	2008-08-27 10:13:01 UTC (rev 3742)
@@ -143,34 +143,35 @@
                         #+:lispworks 'lw:simple-char #-:lispworks 'character
                         'octet))
         (chunkedp (chunked-stream-input-chunking-p (flexi-stream-stream stream))))
-    #+:clisp
-    (setf (flexi-stream-element-type stream) element-type)
-    (multiple-value-prog1 
-        (values (cond ((eql content-length 0) (if textp "" nil))
-                      (content-length
-                       (when chunkedp
-                         ;; see RFC 2616, section 4.4
-                         (error "Got Content-Length header although input chunking is on."))
-                       (let ((result (make-array content-length
-                                                 :element-type element-type
-                                                 :fill-pointer t)))
-                         (setf (fill-pointer result)
-                               (read-sequence result stream))
-                         result))
-                      ((or chunkedp must-close)
-                       ;; no content length, read until EOF (or end of chunking)
-                       (let ((buffer (make-array +buffer-size+
-                                                 :element-type element-type))
-                             (result (make-array 0
-                                                 :element-type element-type
-                                                 :adjustable t)))
-                         (loop for index = 0 then (+ index pos)
-                               for pos = (read-sequence buffer stream)
-                               do (adjust-array result (+ index pos))
-                                  (replace result buffer :start1 index :end2 pos)
-                               while (= pos +buffer-size+))
-                         result)))
-                (chunked-input-stream-trailers stream)))))
+    (values (cond ((eql content-length 0) nil)
+                  (content-length
+                   (when chunkedp
+                     ;; see RFC 2616, section 4.4
+                     (error "Got Content-Length header although input chunking is on."))
+                   (setf (flexi-stream-element-type stream) 'octet)
+                   (let ((result (make-array content-length :element-type 'octet)))
+                     #+:clisp
+                     (setf (flexi-stream-element-type stream) 'octet)
+                     (read-sequence result stream)
+                     (when textp
+                       (setf result
+                             (octets-to-string result :external-format (flexi-stream-external-format stream))
+                             #+:clisp #+:clisp
+                             (flexi-stream-element-type stream) element-type))
+                     result))
+                  ((or chunkedp must-close)
+                   ;; no content length, read until EOF (or end of chunking)
+                   #+:clisp
+                   (setf (flexi-stream-element-type stream) element-type)
+                   (let ((buffer (make-array +buffer-size+ :element-type element-type))
+                         (result (make-array 0 :element-type element-type :adjustable t)))
+                     (loop for index = 0 then (+ index pos)
+                           for pos = (read-sequence buffer stream)
+                           do (adjust-array result (+ index pos))
+                           (replace result buffer :start1 index :end2 pos)
+                           while (= pos +buffer-size+))
+                     result)))
+            (chunked-input-stream-trailers (flexi-stream-stream stream)))))
 
 (defun http-request (uri &rest args
                          &key (protocol :http/1.1)




More information about the Bknr-cvs mailing list