[Libwebsockets] http GET request

Avigail Wilk awilk at kramerav.com
Wed Jun 30 12:37:37 CEST 2021


Hi,

What is the right way to implement RestApi using lws with GET request?
As a response to a GET request I want to return the content of a file (and optionally editing the file's content before sending it).

The way It's implemented in my project is:
when I recognize the Get request in the callback function  (in case LWS_CALLBACK_HTTP) I read the file's content, edit it if needed, and then write it using lws_write function and returning -1;
This worked with libwebsockets v2.0 but not with v4.2.0.
I thought that in v4.2.0 it might be a problem to call lws_write from  LWS_CALLBACK_HTTP,
so instead I used lws_callback_on_writable and in LWS_CALLBACK_HTTP_WRITEABLE I used lws_write. But this didn't solve the problem.

I don't want to use lws_serve_http_file because I want the option to return the content as a string and edit it.

Any idea of what I am doing wrong? Or what is the right way to achieve this?

Many thanks!


This message has been scanned for malware by Websense. www.websense.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210630/19ce2940/attachment.htm>


More information about the Libwebsockets mailing list