[Libwebsockets] two part html

Andy Green andy.green at linaro.org
Tue Aug 19 21:43:32 CEST 2014

On 20 Aug 2014 02:08, "Steve Calfee" <scalfee at mqidentity.com> wrote:
> ________________________________________
> From: Andy Green <extracats at googlemail.com> on behalf of Andy Green <
andy at warmcat.com>
> Sent: Monday, August 18, 2014 9:13 PM
> To: Steve Calfee; libwebsockets at ml.libwebsockets.org
> Subject: Re: [Libwebsockets] two part html
> On 19 August 2014 10:53:37 GMT+08:00, Steve Calfee <scalfee at mqidentity.com>
> >Hi,
> >
> >I think I can do this, but I am not sure. I would like to send a html
> >file with the lws sendfile capability. Then I want to send a string of
> >json I built in my app as the rest of the html.
> >
> >I think all I have to do is when sendfile is done, return 0; then on
> >the next http callback I can send my data. If that is true, what
> >callback code will I get to indicate it is time for me to send my
> >little computed data?
> But you will get trouble I think, if sending the file sets the content
length header the transaction is over after that much was sent.
> -Andy
> Hi Andy,
> Who sets the content-length field? I don't have the source here, but I
will check it later. If it is set by the lws_sendfile routine, I guess I
cannot do it that way.
> As a simpler example, say I split a html file arbitrarily in the middle,
into 2 files. Then in the http callback I call the lws_sendfile routine
twice. Would that work?
> Thanks, Steve
> Hi Andy,
> A follow up. I can now see the source and indeed
libwebsockets_serve_http_file sets the content-length so I cannot use it to
send two parts. I will have to roll my own.
> I don't understand the lws rules on private routines. Can I unroll the
big  libwebsockets_serve_http_file by explicitly handling the start of the
send?  And then use "LWS_VISIBLE int
libwebsockets_serve_http_file_fragment(..." or is that a private function
that should not be used by user level code?
> It isn't that big a deal to do it explicitly in my code, but I always
like to reuse code from libraries if it is possible.

It's separated out like that to indicate we'll make an effort to maintain
the public ones in a way that they still look pretty much the same if
possible in later versions.

The private ones have no such promise they may change or disappear at any

And it's less confusing if people can read libwebsockets.h to understand
what is available.

I think your approach might not be the right way.

How about put your payload in a cookie header or somesuch and just send the
file simply?

Or if you don't send this stuff very often, pick it up in two separate http
requests at different uri paths?

Either way your code gets simpler, more testable and more reliable.


> Thanks, Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20140820/f2398a77/attachment-0001.html>

More information about the Libwebsockets mailing list