[Libwebsockets] [EXTERNAL] Re: http GET request

Avigail Wilk awilk at kramerav.com
Wed Jun 30 17:27:14 CEST 2021

Thanks so much for your answer!
This solved the problem!

From: Paweł Konowalski <pawel.konowalski.delta at gmail.com>
Sent: Wednesday, June 30, 2021 1:52 PM
To: Avigail Wilk <awilk at kramerav.com>; libwebsockets at ml.libwebsockets.org; Andy Green <andy at warmcat.com>
Subject: [EXTERNAL] Re: [Libwebsockets] http GET request


Do you finalize headers before you send the content via lws_write?
See -> lws_finalize_write_http_header(wsi, headers + LWS_PRE, &p, end)


W dniu 30.06.2021, śro o godzinie 10∶37 +0000, użytkownik Avigail Wilk napisał:

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<http://www.websense.com/>


Libwebsockets mailing list

Libwebsockets at ml.libwebsockets.org<mailto:Libwebsockets at ml.libwebsockets.org>


Click here<https://www.mailcontrol.com/sr/ghkKIc2U9nnGX2PQPOmvUj911dVlkoGMDIRhjPoanREUAaqe_rsN7f6DW7FYr26yj-ibO5yjqHMKIUtpuCToCg==> to report this email as spam.
CAUTION:This email originated from outside of the organization.
Do not click links or open attachments unless you recognize the sender and know the content is safe.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210630/2a6a132d/attachment-0001.htm>

More information about the Libwebsockets mailing list