Page 1 of 1

-http construct response in command-event ?

Posted: Fri Nov 30, 2012 4:16 pm
by 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

Re: -http construct response in command-event ?

Posted: Fri Nov 30, 2012 8:12 pm
by Lutz
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:

Code: Select all

;; contents of http-conf.lsp
(command-event (fn (s)
    (print "HTTP/1.0 200 OK\r\n")
    (print "Content-Length: 11\r\n")
    (print "Content-Type: text/html\r\n\r\n")
    (print "Hello World")
    ""
))
start newLISP server like this:

Code: Select all

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.

Re: -http construct response in command-event ?

Posted: Mon Dec 03, 2012 8:29 am
by 2b1
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.