HTTP POST processing
Posted: Thu Jan 13, 2011 12:43 pm
Hi there,
cgi.lsp processes POST parameters using read-line:
Today I tried this when CGI ran under Mathopd and it did not work (or actually I was using web.lsp, but the issue is similar with cgi.lsp): when some data was sent using POST, the script was simply hanging waiting for something. CGI environment provides the length of POST-ed data en CONTENT_LENGTH. So, a (read) should rather be used to collect POST-ed data. For web.lsp, I have a patch. For cgi.lsp, the code might look like this (replacing the code above):
I have not actually tried it, as I'm not using cgi.lsp, but it seems correct.
Thanks.
EDIT: After I submitted the post, I went through the nl-web.c and it seems to me that my changes will not work with newLISP's built in web server's CGI handler, as it does not set the CONTENT_LENGTH variable. Actually it only sets a subset of variables, at least compared to what CGI/1.1 spec says. It might be worth mentioning in the docs that CGI environment variables apart from the mentioned HTTP_HOST, HTTP_USER_AGENT and HTTP_COOKIE (and some other) are not being set.
cgi.lsp processes POST parameters using read-line:
Code: Select all
; get stdin POST method parameters if present
;
(set 'inline (read-line))
(if inline
(set 'params (get-vars inline)))
(if (not params) (set 'params '()))
Code: Select all
; get stdin POST method parameters if present
;
(when (= (env "HTTP_METHOD") "POST")
(read (device) post-data (integer (env "CONTENT_LENGTH")))
(set 'params (get-vars post-data)))
(if (not params) (set 'params '()))
Thanks.
EDIT: After I submitted the post, I went through the nl-web.c and it seems to me that my changes will not work with newLISP's built in web server's CGI handler, as it does not set the CONTENT_LENGTH variable. Actually it only sets a subset of variables, at least compared to what CGI/1.1 spec says. It might be worth mentioning in the docs that CGI environment variables apart from the mentioned HTTP_HOST, HTTP_USER_AGENT and HTTP_COOKIE (and some other) are not being set.