From lam at tuxfamily.org Wed Dec 6 08:47:17 2006 From: lam at tuxfamily.org (lam at tuxfamily.org) Date: Wed, 6 Dec 2006 09:47:17 +0100 (CET) Subject: [drakma-devel] Drakma : Problem saving file Message-ID: <30622.194.51.71.165.1165394837.squirrel@webmail.tuxfamily.org> 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) # 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")) # # T and : CL-USER> (drakma:http-request "http://www.google.com/images/logo_sm.gif" :want-stream t) # 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")) # # 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. From edi at agharta.de Wed Dec 6 09:20:23 2006 From: edi at agharta.de (Edi Weitz) Date: Wed, 06 Dec 2006 10:20:23 +0100 Subject: [drakma-devel] Drakma : Problem saving file In-Reply-To: <30622.194.51.71.165.1165394837.squirrel@webmail.tuxfamily.org> (lam@tuxfamily.org's message of "Wed, 6 Dec 2006 09:47:17 +0100 (CET)") References: <30622.194.51.71.165.1165394837.squirrel@webmail.tuxfamily.org> Message-ID: On Wed, 6 Dec 2006 09:47:17 +0100 (CET), lam at 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. From lam at tuxfamily.org Wed Dec 6 10:51:03 2006 From: lam at tuxfamily.org (lam at tuxfamily.org) Date: Wed, 6 Dec 2006 11:51:03 +0100 (CET) Subject: [drakma-devel] Drakma : Problem saving file In-Reply-To: References: <30622.194.51.71.165.1165394837.squirrel@webmail.tuxfamily.org> Message-ID: <2766.194.51.71.165.1165402263.squirrel@webmail.tuxfamily.org> hello, > On Wed, 6 Dec 2006 09:47:17 +0100 (CET), lam at 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. yes :( in fact the url is in a local server > 2. Which Lisp implementation and which OS are you using? $> sbcl --version SBCL 0.9.14 > 3. 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 > 4. 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. > From edi at agharta.de Thu Dec 7 07:52:49 2006 From: edi at agharta.de (Edi Weitz) Date: Thu, 07 Dec 2006 08:52:49 +0100 Subject: [drakma-devel] Drakma : Problem saving file In-Reply-To: <2766.194.51.71.165.1165402263.squirrel@webmail.tuxfamily.org> (lam@tuxfamily.org's message of "Wed, 6 Dec 2006 11:51:03 +0100 (CET)") References: <30622.194.51.71.165.1165394837.squirrel@webmail.tuxfamily.org> <2766.194.51.71.165.1165402263.squirrel@webmail.tuxfamily.org> Message-ID: On Wed, 6 Dec 2006 11:51:03 +0100 (CET), lam at 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. From edi at agharta.de Mon Dec 18 08:22:26 2006 From: edi at agharta.de (Edi Weitz) Date: Mon, 18 Dec 2006 09:22:26 +0100 Subject: [drakma-devel] Drakma : Problem saving file In-Reply-To: <2766.194.51.71.165.1165402263.squirrel@webmail.tuxfamily.org> (lam@tuxfamily.org's message of "Wed, 6 Dec 2006 11:51:03 +0100 (CET)") References: <30622.194.51.71.165.1165394837.squirrel@webmail.tuxfamily.org> <2766.194.51.71.165.1165402263.squirrel@webmail.tuxfamily.org> Message-ID: On Wed, 6 Dec 2006 11:51:03 +0100 (CET), lam at 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.