[Libwebsockets] How to serve the mounts from the callback?

Andy Green andy at warmcat.com
Fri Jul 26 16:43:59 CEST 2019



On July 26, 2019 6:44:15 AM PDT, necktwi <necktwi at icloud.com> wrote:
>I want my http request to be handled by callback and after analyzing
>the request type then want to forward to the mount mechanism.

Instead of doing that, it's much better to partition your url space into a file mount for / and a dynamic mount at some specific base path, eg, /dyn

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/http-server/minimal-http-server-dynamic/minimal-http-server-dynamic.c#n185

Lws can deal with this mount path  layering if you give the exceptions first and / as a catch-all.

>What is the source file for bin/libwebsockets-test-server? is it
>test-apps/test-server.c? I want to check how leaf.png is served; what
>source file should I've to check?

The test server used to do everything by hand, eg for leaf.jpg

https://libwebsockets.org/git/libwebsockets/tree/test-apps/test-server-http.c?h=v2.4-stable#n290-365
https://libwebsockets.org/git/libwebsockets/tree/test-apps/test-server-http.c?h=v2.4-stable#n564-609

This was a very high bar for people trying to learn the api.  It's all there but it's a big pile of everything.

At v3.0 and later, the minimal examples took over this teaching task.  The old test server was replaced with an implementation using plugins; the same plugins are used on the lwsws that runs libwebsockets.org.  eg

https://libwebsockets.org/git/libwebsockets/tree/plugins/protocol_dumb_increment.c

This is way cleaner and can still be used by including it at build-time, as well as a dynamically loaded plgin on lwsws.  And leaf.jpg is served by a mount.

-Andy

>... Necktwi
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>https://libwebsockets.org/mailman/listinfo/libwebsockets


More information about the Libwebsockets mailing list