[Libwebsockets] POST messages callbacks
mbargauan at comm5g.com
mbargauan at comm5g.com
Tue Mar 9 09:02:14 CET 2021
thank you for valuable help, it works great, and solved the my problem.
There is one question that is dividing in my team and where your opinion could help:
as we have 2 functional activities, one ingesting data from other process and one websocket (deliver updated data and receiving commands from web based gui), we have seen different ways to implement:
one is by having one vhost on one port and a second on a different port,
second is having 2 vhost on the same port,
last is having different threads per functional activity.
We are using 4 core processor, single ethernet port. What is your suggestion on best approach?
From "Andy Green" andy at warmcat.com
To mbargauan at comm5g.com
Cc libwebsockets at ml.libwebsockets.org
Date Wed, 3 Mar 2021 16:00:03 +0000
Subject Re: [Libwebsockets] POST messages callbacks
On 3/3/21 3:03 PM, mbargauan at comm5g.com wrote:
> Thank you, Andy.
> After some more troubleshooting, I can say that my problem arise from
> having "/" as URI and default file is delivered as a normal GET even if
> it is a POST, never calling LWS_CALLBACK_HTTP_BODY.
> Same when URI points to a file that exist in LOCAL_RESOURCE_PATH - eg:
> duplicated index.html as index2.html, file delivered, no
For lws http serving, what is mapped where in the url space is defined
by the lws_http_mount list passed into the vhost creation.
You can bind that mount to your protocol (by setting the mount's
.protocol to the name of your protocol you want to handle it) and have
it get first dibs on anything happening there. Otherwise in the case of
the LWSMPRO_FILE mount and the URL being the exact mount point, like
"/", the mount will handle its mountpoint (and may define a default
sub-url to serve if none given, usually "index.html").
> Any other URI works correctly. providing that protocol at
> LWS_CALLBACK_HTTP does nothing and returns with 0.
> I am not very deep in source code but it seems that decision on calling
> LWS_CALLBACK_HTTP_BODY is taken inside lws_http_action()
> line 1762 if (lwsi_state(wsi) == LRS_ISSUING_FILE)
> return 0;
No all of that is doing its job OK, it's about making the mount prefer
your protocol for / instead. The mount type is LWSMPRO_FILE, it's
saying it's describing what files to server from the mountpoint as its
function, normally the internal dummy callback is enough to make all
that work without any custom protocol.
Attached are the same as before but the txn going to the original / and
the patch on the example with just two one-line edits
- additionally binding the mount to your protocol name
- making the _HTTP callback check for "" (the sub-path from the mount)
instead of /form1 as it normally does
then it's doing what you want without any changes in lws.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Libwebsockets