|Subject:||[lwip-devel] httpd and CGI handler call|
|Date:||Thu, 23 Nov 2017 16:38:50 +0100|
|User-agent:||Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0|
I need to answer to GET /login.cgi?user=admin&pwd=admin request with JSON data. The answer depends on parameters user and pwd passed as query string.
I can't create the answer in fs_open_custom(), because parameters aren't available. Even the answer buffer can't be allocated in fs_open_custom(), because the answer length isn't known yet. In CGI handler I can allocate and create the answer, however I can't set the file content, because I can't access file structure.
One solution is to use LWIP_HTTPD_DYNAMIC_FILE_READ and implement a trivial fs_read_custom(). I think a better solution could be to use LWIP_HTTPD_FILE_STATE, set file->state as file in fs_open_custom() and set file content in CGI handler.
This doesn't work, because in http_init_file() hs->handle, hs->file and hs->left are assigned before calling CGI httpd_cgi_handler().
However this could work if httpd_cgi_handler() is moved before assigning hs->handle, hs->file and hs->left. I tried and it seems it works.
IMHO another good modification could be to pass file to httpd_cgi_handler(), instead of only file->state. In the handler, you will have the access to file and file->state. With this change, you could avoid assigning file->state=file in fs_open_custom() that could be empty.
|[Prev in Thread]||Current Thread||[Next in Thread]|