1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-16 00:00:07 +01:00
libwebsockets/minimal-examples/http-server/minimal-http-server-multivhost
Andy Green 498a4e2bd7 sul: all timed objects use a single pt sul list
wsi timeout, wsi hrtimer, sequencer timeout and vh-protocol timer
all now participate on a single sorted us list.

The whole idea of polling wakes is thrown out, poll waits ignore the
timeout field and always use infinite timeouts.

Introduce a public api that can schedule its own callback from the event
loop with us resolution (usually ms is all the platform can do).

Upgrade timeouts and sequencer timeouts to also be able to use us resolution.

Introduce a prepared fakewsi in the pt, so we don't have to allocate
one on the heap when we need it.

Directly handle vh-protocol timer if LWS_MAX_SMP == 1
2019-08-09 10:12:09 +01:00
..
mount-origin-localhost1 minimal examples: update for CSP best practices 2018-11-21 17:03:29 +08:00
mount-origin-localhost2 minimal examples: update for CSP best practices 2018-11-21 17:03:29 +08:00
mount-origin-localhost3 minimal examples: update for CSP best practices 2018-11-21 17:03:29 +08:00
CMakeLists.txt refactor: most preparation for -DLWS_ROLE_H1=0 2018-04-27 19:16:50 +08:00
minimal-http-server.c sul: all timed objects use a single pt sul list 2019-08-09 10:12:09 +01:00
README.md minimal-http-server-multivhost: add --die-after-vhost option 2018-06-20 16:36:22 +08:00

lws minimal http server multivhost

This creates a single server that creates three vhosts listening on both :7681 and :7682. Two separate vhosts share listening on :7682.

vhost listens on port serves
localhost1 7681 ./mount-origin-localhost1
localhost2 7682 ./mount-origin-localhost2
localhost3 7682 ./mount-origin-localhost3

Notice the last two both listen on 7682. If you visit http://localhost:7682, by default you will get mapped to the first one, localhost2.

However if you edit /etc/hosts on your machine and add

127.0.0.1 localhost3

so that you can visit http://localhost3:7682 in your browser, lws will use the Host: localhost3 header sent by your browser to select the localhost3 vhost for the connection, and you will be served content from ./mount-origin-localhost3

build

 $ cmake . && make

usage

Commandline option Meaning
-d Debug verbosity in decimal, eg, -d15
--die-after-vhost For testing failure handling
 $ ./lws-minimal-http-server-multivhost
[2018/03/16 09:37:20:0866] USER: LWS minimal http server-multivhost | visit http://localhost:7681 / 7682
[2018/03/16 09:37:20:0867] NOTICE: Creating Vhost 'localhost1' port 7681, 1 protocols, IPv6 off
[2018/03/16 09:37:20:0868] NOTICE: Creating Vhost 'localhost2' port 7682, 1 protocols, IPv6 off
[2018/03/16 09:37:20:0869] NOTICE: Creating Vhost 'localhost3' port 7682, 1 protocols, IPv6 off
[2018/03/16 09:37:20:0869] NOTICE:  using listen skt from vhost localhost2

Visit http://localhost:7681 and http://localhost:7682