-http construct response in command-event ?

Started by 2b1, November 30, 2012, 08:16:38 AM

Previous topic - Next topic

2b1

Hi,



the example on the usage of command-event in -http mode shows how to preprocess the request.

Is it possible to create the response in command-event, and let it be sent to the client directly?



And if not, how would I best solve this problem?



Thanks for your answers,



Ingo

Lutz

#1
No sure why you would want do this, because newLISP's built-in web server would take care of headers etc. You need the http-conf.lsp only if you want to filter and or modify requests coming in via the 's' parameter - but you could do the following:



;; contents of http-conf.lsp
(command-event (fn (s)
    (print "HTTP/1.0 200 OKrn")
    (print "Content-Length: 11rn")
    (print "Content-Type: text/htmlrnrn")
    (print "Hello World")
    ""
))

start newLISP server like this:



newlisp httpd-conf.lsp -c -d 8080

for port numbers < 1000 you would need root permissions depending on the OS.



Because the function in 'command-event returns an empty string, newLISP's internal web server never gets called and the response is sent back by  the 'command-event function via port 8080.

2b1

#2
Thank you for the explanation.



My reasoning for asking for this is:



If I'm using a Newlisp webserver, and Newlisp cgi ... why not just load the cgi functions on the start of the webserver? Then I can save the load time on cgi calls.