Re: How to simple exit in CGI?
Jean Louis <[email protected]> Tue, 28 Mar 2017 17:26:34 +0300
| Newsgroups | gmane.lisp.clisp.general |
|---|---|
| Message-ID | <[email protected]> |
On Tue, Mar 28, 2017 at 02:32:48AM +0200, Pascal Bourguignon wrote:
> > without parameters it should simply exit, but exiting seem a problem to me.
>
> You should print out HTTP headers. You can use them to report some status.
>
> Something like:
>
> #!/usr/local/bin/clisp -q -ansi -norc -E utf-8
> ;; -*- mode:lisp;coding:utf-8 -*-
>
> (defun main ()
> (write-string "Content-Type: text/plain
> Content-Length: 0
> Status: 204
>
>
> ")
> (finish-output)
> (ext:exit 0))
>
> (main)
Thank you. Sure, I am sending headers when necessary. If not
necessary, in case of direct call to CGI, I like to send the redirect.
I am waiting on either QUERY_STRING for GET parameters or
*standard-input* for parameters from POST.
However, if there is no QUERY_STRING and no standard input sent, then
I get in trouble.
If I am to use it as script, at least it aborts, and gives me nothing:
wget -O /dev/shm/test "http://localhost/test.cgi"; less /dev/shm/test
--2017-03-28 17:21:18-- http://localhost/test.cgi
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified
Saving to: ‘/dev/shm/test’
/dev/shm/test [ <=> ] 0 --.-KB/s in 0s
2017-03-28 17:21:18 (0.00 B/s) - ‘/dev/shm/test’ saved [0]
and that is "almost" wanted. Yet the execution does not arrive to the
redirect. So the page does not get redirected. Why?
#!/usr/local/bin/clisp -q -ansi -norc -E utf-8
(setf custom:*ansi* t)
(defun main nil
(let ((url "http://localhost")
(query (or (getenv "QUERY_STRING")
(alexandria.0.dev:read-stream-content-into-string *standard-input*))))
(format t "Status: 302 Found~%Location: ~a~%~%" url)
(finish-output)
(exit 0)))
(main)
If I then save it as memory image, exactly this one here below, and
then do following, I get redirect: wget -O /dev/shm/test
"http://localhost/test.cgi?a";
yet if I don't send any parameters, I get displayed:
*** - Ctrl-C: User break
Break 1 [1]>
I would like to understand what is happening.
Jean
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
clisp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/clisp-list