[Libwebsockets] Send http response after parsing request body
andy at warmcat.com
Wed Mar 13 23:28:31 CET 2019
On March 14, 2019 4:28:22 AM GMT+08:00, Kun Zhao <kzhdev at gmail.com> wrote:
>I need to response a POST after parsing the request body. Can I call
>lws_add_http_common_headers and lws_finalize_write_http_header in
>LWS_CALLBACK_HTTP_BODY_COMPLETION? In this case, should I call
>lws_callback_on_writable(wsi) in LWS_CALLBACK_HTTP or in
>LWS_CALLBACK_HTTP_BODY_COMPLETION? In your minimal samples, you simply
>redirect the request to another page. Could you add an example to show
>to properly send a dynamic response after parsing the request body?
Take a look at the demo post protocol plugin, it shows how to do all that.
The minimal examples try to be minimal so it's not hard to see how to do whatever the main point is. But historically the demos were in big monolithic apps... these got mostly split out into clean protocol plugins a while back... so there are more examples to be found in /plugins. These plugins are used in lwsws on https://libwebsockets.org/testserver and built into the now much smaller libwebsockets-test-server
>in addition, when returning the http_callack function, what is the
>of return 0, 1, and -1?
Unless the specific callback interprets it differently, 0 indicates no problem (unhandled callbacks should return 0), and nonzero means something bad happened and the stream (h2) or connection (h1) must be closed.
More information about the Libwebsockets