[Libwebsockets] Send http response after parsing request body

Andy Green andy at warmcat.com
Thu Mar 14 21:09:59 CET 2019



On March 14, 2019 10:32:01 PM GMT+08:00, Kun Zhao <kzhdev at gmail.com> wrote:
>Andy,
>
>Thanks for your response. One more quick question, there is
>log_filepath in
>lws_context_creation_info, when and how this is used? I tried to set it
>but
>no log file is created.

Lws http serving optionally supports per-vhost Apache style access log generation,  if the cmake option LWS_WITH_ACCESS_LOG is enabled and this .log_filepath is non-NULL at vhost creation time.

If you instead want to control where the lwsl_...() lws logs go, you can set the emit function to your own one or some canned ones, including syslog.

https://libwebsockets.org/git/libwebsockets/tree/include/libwebsockets/lws-logs.h#n161-216

-Andy

>Thanks,
>
>On Wed, Mar 13, 2019 at 5:28 PM Andy Green <andy at warmcat.com> wrote:
>
>>
>>
>> On March 14, 2019 4:28:22 AM GMT+08:00, Kun Zhao <kzhdev at gmail.com>
>wrote:
>> >Hi Andy,
>> >
>> >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
>> >how
>> >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.
>>
>>
>>
>https://libwebsockets.org/git/libwebsockets/tree/plugins/protocol_post_demo.c
>>
>> 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
>>
>>
>https://libwebsockets.org/git/libwebsockets/tree/test-apps/test-server.c
>>
>> >in addition, when returning the http_callack function, what is the
>> >meaning
>> >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.
>>
>> -Andy
>>
>> >Thanks,
>> >Kun
>>


More information about the Libwebsockets mailing list