[Libwebsockets] two part html

Steve Calfee scalfee at mqidentity.com
Tue Aug 19 23:11:10 CEST 2014

From: Andy Green <andy.green at linaro.org>
Sent: Tuesday, August 19, 2014 12:43 PM
To: Steve Calfee; libwebsockets at ml.libwebsockets.org
Subject: RE: [Libwebsockets] two part html

On 20 Aug 2014 02:08, "Steve Calfee" <scalfee at mqidentity.com<mailto:scalfee at mqidentity.com>> wrote:
> ________________________________________
> From: Andy Green <extracats at googlemail.com<mailto:extracats at googlemail.com>> on behalf of Andy Green <andy at warmcat.com<mailto:andy at warmcat.com>>
> Sent: Monday, August 18, 2014 9:13 PM
> To: Steve Calfee; libwebsockets at ml.libwebsockets.org<mailto: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<mailto:scalfee at mqidentity.com>> wrote:
> >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 time.

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.


Hi Andy,

I agree intentionally private stuff should stay private.

I don't know how a user can load one web page using two separate http requests.

Also, I don't know how a cookie header could add json or javascript to a web page?

The simplest way to think of it is I want a browser to get two separate html files in one http connection. I think the only way to do this is to read the files in the http callback and do two (or more) sends using something very like  libwebsockets_serve_http_file, but that does match my peculiar needs.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20140819/9399dd99/attachment-0001.html>

More information about the Libwebsockets mailing list