-http construct response in command-event ?

Q&A's, tips, howto's
Locked
2b1
Posts: 2
Joined: Fri Nov 30, 2012 6:27 am

-http construct response in command-event ?

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: -http construct response in command-event ?

Post 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.

2b1
Posts: 2
Joined: Fri Nov 30, 2012 6:27 am

Re: -http construct response in command-event ?

Post 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.

Locked