Re: using the http server to return xml
On Sat, Oct 04, 2008 at 02:32:40PM +0100, Tomas Hlavaty wrote: > $ curl -i localhost:8080/@mydata2 > HTTP/1.1 200 OK > Server: PicoLisp > ... BTW, a similar result (HTTP/1.0 only, but useful for further processing with Lisp) can be achieved with : (client "localhost" 8080 "@mydata2" (out NIL (echo))) HTTP/1.0 200 OK Server: PicoLisp ... Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
Hi Konrad > I still don't quite follow what curl is supposed to be showing is > wrong with my use of http header. I'm installing it now and will dig > further. I'm determined to get this thing working right. curl shows you what response is "seen" by the browser. Getting back to your previous example: === $ curl -i localhost:8080/@mydata2 HTTP/1.1 200 OK Server: PicoLisp Date: Fri, 03 Oct 2008 12:29:56 GMT Cache-Control: max-age=1 Content-Type: text/xml; charset=utf-8 Transfer-Encoding: chunked curl: (56) Received problem 2 in the chunky parser === curl reports that your code was sending Transfer-Encoding: chunked header but the data were not sent in the chunked format actually, thus the error message. So you have two options: 1) Switching off chunking (i.e. not sending the Transfer-Encoding: chunked header) as Alex has advised 2) or sending the XML data in the right (chunked) format, see mydata3 function in my example before (using ht:Out function). Cheers, Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
Hi Konrad, > xml files arround like this I guess I can make these settings globally > for the application. I'm not entierly sure what the implications are. It is possible to set '*Http1' and '*Chunked' globally, but you must sure that this takes place each time after a HTTP GET or POST request, because they are set internally by the server (in '_htHead') according to the type of request. Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
On Sat, Oct 04, 2008 at 10:22:49PM +1000, konrad Zielinski wrote: > I'm guessing this means that Mime remains whatever it was when server > started and my setting of mime was taking place in a forked process > for the request, and hence was not actually affecting anything. I am Yes, this was probably the reason. -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
Thanks Alex, the following fixed the problem. As the bulk of my app will be sending xml files arround like this I guess I can make these settings globally for the application. I'm not entierly sure what the implications are. but I suspect their not too important providing my documents don't grow to some ridiculous size. regards Konrad. On 04/10/2008, Alexander Burger <[EMAIL PROTECTED]> wrote: > On Fri, Oct 03, 2008 at 09:32:43PM +1000, konrad Zielinski wrote: >> (de mydata2 () >> (httpHead "text/xml; charset=utf-8" 1) >> (xml? T) >> (xml '(root NIL "Document 2")) >> ) >> >> mydata works perfectly. mydata2 fails to roduce any output. Now the > > Not sure what the problem is, but two things come to mind: > > 1. In which context is 'mydata2' called? If the connection is not closed >for some reason, you could try to call (flush) after sending the >data. > > 2. If the initial request from the browser was HTTP/1.1, then the global >'*Http1' is set to '1', causing the picoLisp server to initiate a >chunked transfer. You could try > > (let (*Http1 0 *Chunked NIL) > (httpHead "text/xml; charset=utf-8" 1) ) > > Cheers, > - Alex > -- > UNSUBSCRIBE: mailto:[EMAIL PROTECTED] > -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
I think my problem with setting mime types originally was due to basing my code on the initial hello world example, where the html function is called bare inside project.l. In this model the call to server is on the command line. I'm guessing this means that Mime remains whatever it was when server started and my setting of mime was taking place in a forked process for the request, and hence was not actually affecting anything. I am guessing here as I havn't read the http code in detail yet. Now that I'm doing somthing similer to the sample application and having a app.l which does all the loading and calls server from inside picoLisp code I suspect things will work correctly. I still don't quite follow what curl is supposed to be showing is wrong with my use of http header. I'm installing it now and will dig further. I'm determined to get this thing working right. On 04/10/2008, Alexander Burger <[EMAIL PROTECTED]> wrote: > Hi Konrad, > >> I've got it returning an actual .xml file ok. (had to modify the >> definition of *Mimes directly as calling (mime "xml" "text/xml" 1) >> didn't seem to have any effect. > > Though this is not central to your question, it is strange because it > should work. > > Where in your code did you call 'mime'? Should be ok anytime after > "lib/http.l" is loaded. > > Cheers, > - Alex > -- > UNSUBSCRIBE: mailto:[EMAIL PROTECTED] > -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
On Fri, Oct 03, 2008 at 09:32:43PM +1000, konrad Zielinski wrote: > (de mydata2 () > (httpHead "text/xml; charset=utf-8" 1) > (xml? T) > (xml '(root NIL "Document 2")) > ) > > mydata works perfectly. mydata2 fails to roduce any output. Now the Not sure what the problem is, but two things come to mind: 1. In which context is 'mydata2' called? If the connection is not closed for some reason, you could try to call (flush) after sending the data. 2. If the initial request from the browser was HTTP/1.1, then the global '*Http1' is set to '1', causing the picoLisp server to initiate a chunked transfer. You could try (let (*Http1 0 *Chunked NIL) (httpHead "text/xml; charset=utf-8" 1) ) Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
Hi Konrad, > I've got it returning an actual .xml file ok. (had to modify the > definition of *Mimes directly as calling (mime "xml" "text/xml" 1) > didn't seem to have any effect. Though this is not central to your question, it is strange because it should work. Where in your code did you call 'mime'? Should be ok anytime after "lib/http.l" is loaded. Cheers, - Alex -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
Hi Konrad, > mydata works perfectly. mydata2 fails to roduce any output. try curl to see what is going wrong: === $ curl -i localhost:8080/@mydata HTTP/1.0 200 OK Content-Type: text/xml; charset=utf-8 Hello Using XML === $ curl -i localhost:8080/@mydata2 HTTP/1.1 200 OK Server: PicoLisp Date: Fri, 03 Oct 2008 12:29:56 GMT Cache-Control: max-age=1 Content-Type: text/xml; charset=utf-8 Transfer-Encoding: chunked curl: (56) Received problem 2 in the chunky parser === This function works: (de mydata3 () (httpHead "text/xml; charset=utf-8" 1) (ht:Out *Chunked (xml? T) (xml '(root NIL "Document 3" $ curl -i localhost:8080/@mydata3 HTTP/1.1 200 OK Server: PicoLisp Date: Fri, 03 Oct 2008 12:34:47 GMT Cache-Control: max-age=1 Content-Type: text/xml; charset=utf-8 Transfer-Encoding: chunked Document 3 Cheers, Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
I managed to get this far since my first post. My laster mystery is the following two functions (de mydata () (prinl "HTTP/1.0 200 OK^M") (prinl "Content-Type: text/xml; charset=utf-8") (prinl "^M") (xml? T) (xml '(root NIL "Hello Using XML")) ) (de mydata2 () (httpHead "text/xml; charset=utf-8" 1) (xml? T) (xml '(root NIL "Document 2")) ) mydata works perfectly. mydata2 fails to roduce any output. Now the thing is the built in html function uses httpHead quite sucessfully and if I connect with psh and call mydata2 it prints a http header that looks valid. Indeed if I take the printed lines and duplicate them exactly as prinl statements then things work fine as well. I must be doing something wrong here but can't for the life of me see what it might be. On 03/10/2008, Tomas Hlavaty <[EMAIL PROTECTED]> wrote: > Hi Konrad, > >> http://localhost:8080/@xmldata > >> and get the intended xml data back. So far I've had no luck getting >> the server to successfully call a function and get anything back. > > try this for example: > > === > > #!bin/picolisp lib.l > > (load "ext.l" "lib/http.l" "lib/xhtml.l") > > (de xmldata () >(prinl "HTTP/1.0 200 OK^M") >(prinl "Server: PicoLisp^M") >(prinl "Date: Fri, 3 Oct 2008 10:53:58 GMT^M") >(prinl "Cache-Control: max-age=0^M") >(prinl "Cache-Control: no-cache^M") >(prinl "Content-Type: text/xml; charset=utf-8^M") >(prinl "^M") >(prinl "are?")) > > (de start () >(html 0 "xmldata test" NIL NIL > ( NIL ( "xmldata" "@xmldata") ) ) ) > > (server 8080 "@start") > > === > > Execute the script from your picolisp directory, then click on the > xmldata link. You should get an XML as returned by xmldata function. > > The next step is to fix the http header and get the xml from a file. > > Cheers, > > Tomas > -- > UNSUBSCRIBE: mailto:[EMAIL PROTECTED] > -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]
Re: using the http server to return xml
Hi Konrad, > http://localhost:8080/@xmldata > and get the intended xml data back. So far I've had no luck getting > the server to successfully call a function and get anything back. try this for example: === #!bin/picolisp lib.l (load "ext.l" "lib/http.l" "lib/xhtml.l") (de xmldata () (prinl "HTTP/1.0 200 OK^M") (prinl "Server: PicoLisp^M") (prinl "Date: Fri, 3 Oct 2008 10:53:58 GMT^M") (prinl "Cache-Control: max-age=0^M") (prinl "Cache-Control: no-cache^M") (prinl "Content-Type: text/xml; charset=utf-8^M") (prinl "^M") (prinl "are?")) (de start () (html 0 "xmldata test" NIL NIL ( NIL ( "xmldata" "@xmldata") ) ) ) (server 8080 "@start") === Execute the script from your picolisp directory, then click on the xmldata link. You should get an XML as returned by xmldata function. The next step is to fix the http header and get the xml from a file. Cheers, Tomas -- UNSUBSCRIBE: mailto:[EMAIL PROTECTED]