[Libwebsockets] serving compressed http response from a zip archive
per at bothner.com
Mon Feb 13 18:41:59 CET 2017
On 02/11/2017 05:00 PM, Andy Green wrote:
> The main thing that will help stitch this in is lws file serving arrangements have a thin VFS between the code doing the serving and the filesystem, via a file_ops type struct of callbacks
Is there any particular advantage to using the VFS hook, rather than
just calling lws_write etc?
I cobbled together a VFS solution, though it's not quite working, due (I think)
to the error handling. (I'm getting a timeout when a missing favicon.ico is requested.)
I think it will be easier and cleaner to just modify the existing lws_write support
used for "compiled-in" resources.
The VFS layer isn't really usable as a general VFS layer. The problem is lws_filefd_type
is platform-specific and not extendable. I couldn't find any clean way to distinguish
the zip-based files from native files.
I implemented a Unix-only kludge where file id's above 1000 are mapped to a table:
#define MAX_OPEN_MEM_FILES 32
struct open_mem_file open_mem_files[MAX_OPEN_MEM_FILES];
#define lws_filefd_to_mem_file(FD) \
((FD) >= 1000 ? &open_mem_files[(FD)-1000] : NULL)
#define mem_file_to_lws_filefd(MEM) (((MEM)-&open_mem_files)+1000)
This is pretty ugly, and only works when lws_filefd_type is an int.
(I haven't looked yet at the optimization of shipped compressed data.
The decompress-on-the-server mode is needed regardless.)
per at bothner.com http://per.bothner.com/
More information about the Libwebsockets