hello, i make some test with drakma and i have a problem with http-request :
CL-USER> (with-open-file (os (format nil "/tmp/~A.png" "tttt") :direction :output :if-exists :supersede :element-type 'unsigned-byte) (multiple-value-bind (body-stream status-code headers uri stream must-close) (drakma:http-request "http://stats-dev/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png" :want-stream t :force-binary t :content-length t) (declare (ignore headers uri stream must-close)) (when (= status-code 200) (format t "Type ~A~%" (type-of body-stream)) (loop for c = (read-byte body-stream nil) until (null c) do (progn (format t "Write ~%") (write-byte c os))) (close body-stream)))) Type FLEXI-IO-STREAM T
after i try with another image :
CL-USER> (with-open-file (os (format nil "/tmp/~A.png" "tttt") :direction :output :if-exists :supersede :element-type 'unsigned-byte) (multiple-value-bind (body-stream status-code headers uri stream must-close) (drakma:http-request "http://www.google.com/images/logo_sm.gif" :want-stream t :force-binary t :content-length t) (declare (ignore headers uri stream must-close)) (when (= status-code 200) (format t "Type ~A~%" (type-of body-stream)) (loop for c = (read-byte body-stream nil) until (null c) do (progn (format t "Write ~%") (write-byte c os))) (close body-stream)))) Type FLEXI-IO-STREAM Write Write Write Write Write Write [...] Write Write T
and the file /tmp/tttt.png contains the google's logo. With the first request, the file is empty.
Here it is the differents between the 2 requests :
CL-USER> (drakma:http-request "http://stats-dev/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png" :want-stream t) #<FLEXI-STREAMS:FLEXI-IO-STREAM {B0F1BF9}> 200 ((:DATE . "Tue, 05 Dec 2006 18:09:17 GMT") (:SERVER . "Apache/1.3.34 (Debian) PHP/4.4.4-6 mod_jk/1.2.18 mod_ssl/2.8.25 OpenSSL/0.9.8c mod_perl/1.29") (:CONNECTION . "close") (:TRANSFER-ENCODING . "chunked") (:CONTENT-TYPE . "image/png")) #<URI http://stats-dev/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png%3E #<FLEXI-STREAMS:FLEXI-IO-STREAM {B0F1BF9}> T
and :
CL-USER> (drakma:http-request "http://www.google.com/images/logo_sm.gif" :want-stream t) #<FLEXI-STREAMS:FLEXI-IO-STREAM {B13C631}> 200 ((:CONTENT-TYPE . "image/gif") (:LAST-MODIFIED . "Wed, 07 Jun 2006 19:38:24 GMT") (:EXPIRES . "Sun, 17 Jan 2038 19:14:07 GMT") (:SERVER . "GWS/2.1") (:CONTENT-LENGTH . "4707") (:DATE . "Tue, 05 Dec 2006 18:10:07 GMT")) #<URI http://www.google.com/images/logo_sm.gif%3E #<FLEXI-STREAMS:FLEXI-IO-STREAM {B13C631}> T
i see that in the request which have a problem content-length is not sended. but i don't really understand why the first image is empty.
thanks if someone understand my problem.
On Wed, 6 Dec 2006 09:47:17 +0100 (CET), lam@tuxfamily.org wrote:
i make some test with drakma and i have a problem with http-request :
(drakma:http-request "http://stats-dev/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png" :want-stream t :force-binary t :content-length t)
The :CONTENT-LENGTH argument is useless in your case, because you don't send a content body to the server.
I think that what you're trying to do should work, but you don't provide enough information to reproduce your problem.
1. "http://stats-dev/" is an URL that doesn't work for me.
2. Which Lisp implementation and which OS are you using?
3. Are you using the newest versions of Drakma, FLEXI-STREAMS, and Chunga?
4. Have you considered to use *HEADER-STREAM* to see if you're maybe redirected?
Cheers, Edi.
hello,
On Wed, 6 Dec 2006 09:47:17 +0100 (CET), lam@tuxfamily.org wrote:
i make some test with drakma and i have a problem with http-request :
(drakma:http-request "http://stats-dev/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png" :want-stream t :force-binary t :content-length t)
The :CONTENT-LENGTH argument is useless in your case, because you don't send a content body to the server.
I think that what you're trying to do should work, but you don't provide enough information to reproduce your problem.
- "http://stats-dev/" is an URL that doesn't work for me.
yes :( in fact the url is in a local server
- Which Lisp implementation and which OS are you using?
$> sbcl --version SBCL 0.9.14
- Are you using the newest versions of Drakma, FLEXI-STREAMS, and Chunga?
yes i have deleted all previous version, and i have install chunga, flexi-streams and drakma with asdf-install : drakma: 0.5.4 flexi-streams: 0.8.0 chunga: 0.2.1
- Have you considered to use *HEADER-STREAM* to see if you're maybe redirected?
i make another test with the newest versions and *HEADER-STREAM* :
CL-USER> (with-open-file (os (format nil "/tmp/~A.png" "foo") :direction :output :if-exists :supersede :element-type 'unsigned-byte) (setf drakma:*header-stream* *standard-output*) (multiple-value-bind (body-stream status-code headers uri stream must-close) (drakma:http-request "http://stats-dev.lam/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png" :want-stream t) (declare (ignore headers uri stream must-close)) (when (= status-code 200) (format t "Type ~A~%" (type-of body-stream)) (loop for c = (read-byte body-stream nil) until (null c) do (progn (format t "Write ~%") (write-byte c os))) (close body-stream))))
GET /cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png HTTP/1.1 Host: stats-dev.lam User-Agent: Drakma/0.5.4 (SBCL 0.9.14; Linux; 2.6.15-23-686; http://weitz.de/drakma/) Accept: */* Connection: close
HTTP/1.1 200 OK Date: Wed, 06 Dec 2006 10:48:50 GMT Server: Apache/1.3.34 (Debian) PHP/4.4.4-6 mod_jk/1.2.18 mod_ssl/2.8.25 OpenSSL/0.9.8c mod_perl/1.29 Connection: close Transfer-Encoding: chunked Content-Type: image/png
Type FLEXI-IO-STREAM T
Cheers, Edi.
On Wed, 6 Dec 2006 11:51:03 +0100 (CET), lam@tuxfamily.org wrote:
in fact the url is in a local server
OK, so I won't be able to debug it... :(
Would you be able to find some public URL that serves binary files with chunked encoding and shows the same symptoms for you?
Cheers, Edi.
On Wed, 6 Dec 2006 11:51:03 +0100 (CET), lam@tuxfamily.org wrote:
(multiple-value-bind (body-stream status-code headers uri
stream must-close) (drakma:http-request "http://stats-dev.lam/cgi-bin/view_image.cgi?filename=/tmp/sms_5Avkjm.png" :want-stream t) (declare (ignore headers uri stream must-close))
BTW, you can just write
(multiple-value-bind (body-stream status-code) (drakma:http-request ...)
here and leave out the DECLARE
So, I tried your example with this URL
http://zappa.agharta.de/test.html
which (although it says ".html") servers a JPEG image with chunked encoding, i.e. without a Content-Length header. Works fine for me with LWW 5.0. Let me know if it works for you.
Cheers, Edi.