https://github.com/warmcat/libwebsockets/issues/526
On master, cleanups and refactor mean the last two problems already
don't exist (array is gone from main.c and http.c is deleted)
Signed-off-by: Andy Green <andy@warmcat.com>
This is used to confirm that SSL client connections can coexist with
a vhost doing serving.
To set it up,
/*
* This is a bit fiddly...
*
* 0) If you want the wss:// test to work, make sure the vhost is marked with
* enable-client-ssl if using lwsws, or call lws_init_vhost_client_ssl() on
* the vhost if you're doing it by hand.
*
* 1) enable the protocol on a vhost
*
* "ws-protocols": [{
* "client-loopback-test": {
* "status": "ok"
* }, ...
*
* the vhost should listen on 80 (ws://) or 443 (wss://)
*
* 2) mount the http part of the test one level down on the same vhost, eg
* {
* "mountpoint": "/c",
* "origin": "callback://client-loopback-test"
* }
*
* 3) Use a browser to visit the mountpoint with a URI attached for looping
* back, eg, if testing on localhost
*
* http://localhost/c/ws://localhost
* https://localhost/c/wss://localhost
*
* 4) The HTTP part of this test protocol will try to do the requested
* ws client connection, to the same test protocol on the same
* server.
*/
Results should look like this
lwsws[29938]: client connection to localhost:443 with ssl: 1 started
lwsws[29938]: server part: LWS_CALLBACK_ESTABLISHED
lwsws[29938]: checking client ext permessage-deflate
lwsws[29938]: instantiating client ext permessage-deflate
lwsws[29938]: Client connection established
lwsws[29938]: Client connection received 7 from server 'Made it'
Signed-off-by: Andy Green <andy@warmcat.com>
Also add lwsws "enable-client-ssl": "1" vhost option to match.
Client cert iclient ssl is not supported in lwsws, if someone wants it, it can be added.
Signed-off-by: Andy Green <andy@warmcat.com>
Actually lwsws doesn't need his own protocol handler even for http
any more. The default http handler in lws should do everything.
Move the cgi routing into lws default http protocol handler, and
delete lwsws one. Remove all protocols from lwsws so the lws
default one gets used.
With this, and the earlier move of lejp into lws, lwsws itself
becomes 15.5KB of x86_64 (mainly conf parsing).
Signed-off-by: Andy Green <andy@warmcat.com>
lejp is already in lws as part of lwsws. However it's too generally useful
to just put directly in lwsws, it will lead to multiple copies of the source
in differet subprojects.
This moves it directly into lws, lwsws now gets it from there.
Like lwsws, by default at cmake it is disabled. Selecting LWS_WITH_LWSWS now
selects LWS_WITH_LEJP and you can set that at cmake individually as well.
Signed-off-by: Andy Green <andy@warmcat.com>
Until now lws has finished the HTTP transaction when the POST body was
completely received.
However that needlessly makes it impossible to send a HTTP 200 and a
response without a redirect.
This changes lws behaviour after sending the LWS_CALLBACK_HTTP_BODY_COMPLETION
callback to no longer terminate the HTTP transaction.
If you want the old behaviour, you can terminate the transaction with
lws_http_transaction_completed() in the LWS_CALLBACK_HTTP_BODY_COMPLETION
callback.
Otherwise it's now possible to call lws_callback_on_writable() from
LWS_CALLBACK_HTTP_BODY_COMPLETION.
Signed-off-by: Andy Green <andy@warmcat.com>
- libuv socket init binding was missing for client
- failures like no ws protocol match are deferred until the
ah is bound. Check for these failures and make sure we
tell the guy trying to set up the client connection the
wsi is NULL if it has already failed and closed.
- pfd.events was not initialized for the client init path
With this general client function is more robust but also
client connections work properly with libuv.
Signed-off-by: Andy Green <andy@warmcat.com>
If for some reason we exit before the protocol init action
(which is delayed for libuv) we should not send the protocol
destroy messages
Signed-off-by: Andy Green <andy@warmcat.com>
While checking with ab, I found
commit 30cdb3ac8f
Author: Justin Chen <justinchen00@github.invalid.com>
Date: Thu Apr 14 21:40:53 2016 +0800
recv treat zero return as error
https://github.com/warmcat/libwebsockets/issues/475
turned ab performance to crap, reverting it made everything fast again.
recv manpage says there is three ways to get zero returned
1) When a stream socket peer has performed an orderly shutdown, the return value will be 0 (the traditional "end-of-file"
return).
2) Datagram sockets in various domains (e.g., the UNIX and Internet domains) permit zero-length datagrams. When such a
datagram is received, the return value is 0.
3) The value 0 may also be returned if the requested number of bytes to receive from a stream socket was 0.
we can't just assume it means the peer shut down.
If the peer shut down, then the event loop should get an event on the socket like POLLHUP and deal with it that way.
So the patch mentioned above is simply reverted here.
Signed-off-by: Andy Green <andy@warmcat.com>
AG: adapt to use switch on existing test-server-libuv app
AG: correct the foreign lifecycle to be valgrind clean
This adds a switch -f --foreign that makes the test-server-libuv test
create his own libuv loop outside of lws, and use lws on it before
destroying lws and then his own loop.
If selected, the foreign loop runs for 5s before lws and 10s after
lws is stopped, for testing purposes.
Signed-off-by: Denis Osvald <denis.osvald@sartura.hr>
If OOT lws plugins will be packaged as separate projects,
they're going to want to install their plugins somewhere
that makes sense for the package instead of one big lws
plugin dir.
This patch changes info to have a const char ** to a NULL
terminated array of directories it should search for
plugins. lwsws knows about this and you can add to the
dir array using config fragments like
{
"global": {
"plugin-dir": "/usr/local/share/coherent-timeline/plugins"
}
}
if the config fragment in /etc/lwsws/conf.d/ is also managed by the
package with the plugin, it can very cleanly add and remove itself
from lwsws based on package install status.
Signed-off-by: Andy Green <andy@warmcat.com>
Move the dummy stub protocol into the library as the default
if NULL protocols given, since that is likely to become popular.
Signed-off-by: Andy Green <andy@warmcat.com>
No dependency on test-server.h (just libwebsockets.h and getopt.h / syslog.h)
No need for any user callback code and all in one short file.
Signed-off-by: Andy Green <andy@warmcat.com>
There's no reason to not have the mounts linked list init also in the info
struct, rather than provide as a paramater to lws_create_vhost(). Now
is a good time to normalize that since this api only exists in master.
This also allows oldstyle "do everything at context creation time in one
vhost" guys to leverage mounts.
Also there's no reason the mounts linked-list pointer and all uses in lws
are non-const, so make them all explicitly const *.
Update the info struct docs to clarify which members are used when creating
a vhost and which for context creation.
Signed-off-by: Andy Green <andy@warmcat.com>