[Libwebsockets] Error When Serving Large Files via HTTP

Chad Cravens chad.cravens at ossys.com
Wed Dec 17 02:31:52 CET 2014


I provided a link to a screenshot of the error that I'm having using Chrome
when attempting to load leaf.jpg from the test server:

http://postimg.org/image/o1mktuxod/

On Mon, Dec 15, 2014 at 9:57 PM, Andy Green <andy at warmcat.com> wrote:
>
>
>
> On 16 December 2014 10:18:54 GMT+08:00, Chad Cravens <
> chad.cravens at ossys.com> wrote:
> >When attempting to serve large files (~ >500K) using the
> >libwebsockets_serve_http_file() method, most of the time the call will
> >hang
> >causing chrome to issue a ERR_CONTENT_LENGTH_MISMATCH error.
> >
> >This happens most of the time, but about every 8-10 browser refreshes
> >the
> >entire file is served without a problem. I noticed that this same error
> >occurs in the example application libwebsockets-test-server that is
> >built
> >when compiling libwebsockets from source on my MacOSX.
> >
> >The following is the code I am using to serve the file:
> >
> >Log::instance()->logDebug("SERVING HTTP FILE: " + resource);
> >ret = libwebsockets_serve_http_file(context, wsi, resource.c_str(),
> >mime.c_str(), "");
> >Log::instance()->logDebug("SERVED HTTP FILE: " + resource);
> >
> >I also put debug statements for every callback made. I noticed that
> >when
> >properly serving large files the debug output looks like the following:
> >
> >[LOG_DEBUG] SERVING HTTP FILE: deps.js
> >LWS_CALLBACK_HTTP_FILE_COMPLETION
> >[LOG_DEBUG] SERVED HTTP FILE: deps.js
> >RESULT OF HTTP: 1
> >
> >However, when there is an error serving the file as stated above, the
> >callback output looks like the following:
> >[LOG_DEBUG] SERVING HTTP FILE: deps.js
> >LWS_CALLBACK_LOCK_POLL
> >LWS_CALLBACK_CHANGE_MODE_POLL_FD
> >LWS_CALLBACK_UNLOCK_POLL
> >LWS_CALLBACK_LOCK_POLL
> >LWS_CALLBACK_CHANGE_MODE_POLL_FD
> >LWS_CALLBACK_UNLOCK_POLL
> >[LOG_DEBUG] SERVED HTTP FILE: deps.js
> >LWS_CALLBACK_LOCK_POLL
> >LWS_CALLBACK_CHANGE_MODE_POLL_FD
> >LWS_CALLBACK_UNLOCK_POLL
> >RESULT OF HTTP: 0
> >
> >When there is an error there additional callbacks that are called an
> >apparently I am not handling the buffering properly. For a while I have
> >been trying to work the issue and figure out how to properly handle
> >buffering and serving large files via HTTP.
> >
> >Any guidance in my approach or examples / documentation would be
> >GREATLY
> >appreciated!!
>
> I added leaf.jpg in the test server ("click here to get sent a large file"
> on the test server page) to provide a test case for exactly this.  It's
> like 2.5MB IIRC.
>
> What happens with everything else the same but give Chrome leaf.jpg from
> the test server?
>
> -Andy
>
> >Kindest Regards,
> >Chad
>
>

-- 
[image: http://www.ossys.com] <http://www.ossys.com>
[image: http://www.linkedin.com/company/open-source-systems-llc]
<http://www.linkedin.com/company/open-source-systems-llc>   [image:
https://www.facebook.com/OpenSrcSys] <https://www.facebook.com/OpenSrcSys>
   [image: https://twitter.com/OpenSrcSys] <https://twitter.com/OpenSrcSys>
     [image: http://www.youtube.com/OpenSrcSys]
<http://www.youtube.com/OpenSrcSys>   [image: http://www.ossys.com/feed]
<http://www.ossys.com/feed>   [image: contact at ossys.com] <contact at ossys.com>
Chad Cravens
(843) 291-8340
chad.cravens at ossys.com
http://www.ossys.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20141216/64416333/attachment-0001.html>


More information about the Libwebsockets mailing list