1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00
Commit graph

571 commits

Author SHA1 Message Date
Andy Green
aa4143aebd lws_diskcache: split generic parts from gitohashi into lws 2018-11-12 15:24:42 +08:00
Andy Green
47579b5306 gcc 8.2.0: ensure port always defined to something 2018-11-07 19:30:37 +08:00
Andy Green
79ea44704c server: check lws_hdr_copy return and cleanup 2018-11-07 17:02:09 +08:00
Andy Green
cbb8b1d3e9 LWS_WITH_ASAN
This lets you build using the runtime Address Sanitizer in gcc.

LWS is heavily tested with valgrind routinely during development.  But ASAN
did find some theoretical-only issues with shifting, strictly ~(1 << 31) is
a signed int, it should be ~(1u << 31).  Gcc does the same for both, but it's
good to have the ability to find these.
2018-11-03 14:47:48 +08:00
Andy Green
27ae132e7b http: add callback to allow upgrade reject
https://github.com/warmcat/libwebsockets/issues/1415
2018-10-31 13:45:00 +08:00
Andy Green
ba612c3df6 http: return 415 instead of hang up if no mimetype for fileserve
Change the err log for this to info, since it makes clear what the problem is now at the client.
2018-10-31 13:44:45 +08:00
Andy Green
93d4e186c2 openssl tls1.3: allow setting ciphersuites at context creation time
https://github.com/warmcat/libwebsockets/issues/1440
2018-10-27 08:05:21 +08:00
Andy Green
1f1314160a lws_hdr_copy: ensure enough extra space
Audit all lws_hdr_copy() usages inside lws and make sure we
take care about it failing.

Also since the patch around aggregation of headers by ',',
lws_hdr_copy() needs a little more space in the output buffer,
adjust one place where that caused it to start failing in an
exact-sized buffer.
2018-10-26 16:14:30 +08:00
Andy Green
20fb55934b client vhost OpenSSL set and clear options
https://github.com/warmcat/libwebsockets/issues/1438
2018-10-26 13:55:36 +08:00
Andy Green
d3bc2c3f4f fulltext search 2018-10-26 13:53:28 +08:00
Andy Green
602b0934c8 fulltext search 2018-10-26 13:50:53 +08:00
Andy Green
14764ccbe2 ws client: apply tokenize to upgrade header
Switches to use lws_hdr_copy() for the case the header is fragmented

See also https://github.com/warmcat/libwebsockets/issues/1435
2018-10-18 06:30:07 +08:00
Alexander Bruines
ed00704566 lws_serve_http_file: skip adding cache control if h1 other_headers do it 2018-10-16 05:05:54 +08:00
Andy Green
da444d04d1 lws_time_in_microseconds: export
Rename time_in_microseconds() and export the internal
api as lws_time_in_microseconds()
2018-10-14 06:15:36 +08:00
Andy Green
d702b83d10 uv: allocate watcher
Until now the uv watcher has been composed in the wsi.

This works fine except in the case of a client wsi that
meets a redirect when the event loop is libuv with its
requirement for handle close via the event loop.

We want to reuse the wsi, since the originator of it has
a copy of the wsi pointer, and we want to conceal the
redirect.  Since the redirect is commonly to a different
IP, we want to keep the wsi alive while closing its
socket cleanly.  That's not too difficult, unless you are
using uv.

With UV the comoposed watcher is a disaster, since after
the close is requested the wsi will start to reconnect.
We tried to deal with that by copying the uv handle and
freeing it when the handle close finalizes.  But it turns
out the handle is in a linked-list scheme in uv.

This patch hopefully finally solves it by giving the uv
handle its own allocation from the start.  When we want
to close the socket and reuse the wsi, we simply take
responsibility for freeing the handle and set the wsi
watcher pointer to NULL.
2018-10-13 12:43:13 +08:00
Andy Green
b5227df2d7 client proxy: offset query args 2018-10-13 12:43:13 +08:00
Andy Green
d03c57b87f quench logging 2018-10-13 08:16:27 +08:00
Andy Green
33a6034875 codacy: minor fixes 2018-10-13 08:16:27 +08:00
Andy Green
3696480b57 ws upgrade hs: require Host hdr 2018-10-13 08:16:27 +08:00
Andy Green
db827733c3 h1 ws client: produce CONNECTION 2018-10-13 08:16:27 +08:00
Andy Green
7b9e6c70f7 ws-upgrade-hs: check connection header
This header, and ws requirement, only exists on h1.
2018-10-13 08:16:27 +08:00
Andy Green
f0418c62bf lws_tokenize: convert ws protocol parsing 2018-10-13 08:16:27 +08:00
Andy Green
6cd80f9fc7 lws_tokenize 2018-10-13 08:16:27 +08:00
Andy Green
31dfc4aa12 role: dbus
This adds support for the integrating libdbus into the lws event loop.

Unlike the other roles, lws doesn't completely adopt the fd and libdbus insists
to retain control over the fd lifecycle.  However libdbus provides apis for
foreign code (lws) to provide event loop services to libdbus for the fd.

Accordingly, unlike the other roles rx and writeable are not subsumed into
lws callback messages and the events remain the property of libdbus.

A context struct wrapper is provided that is available in the libdbus
callbacks to bridge between the lws and dbus worlds, along with
a minimal example dbus client and server.
2018-10-13 08:16:27 +08:00
Anzey
bbbdc85421 ws: protocol list whitespace fix
https://github.com/warmcat/libwebsockets/issues/1423#issuecomment-427690736
2018-10-13 08:16:27 +08:00
Andy Green
074b8f3881 client: oom4: unify with __lws_free_wsi 2018-10-07 13:12:44 +08:00
Andy Green
2f8efa1082 auth: record basic auth user
This causes the WSI_TOKEN_HTTP_AUTHORIZATION content to be
replaced by the plaintext username that succeeded to be
authenticated.
2018-10-02 10:52:09 +08:00
Andy Green
5760a562d8 ws-over-h2: unbreak 2018-10-02 05:42:56 +08:00
negativekelvin
9b35bc171b esp32: blows if allowed lejp 2018-10-01 15:50:50 +08:00
Andy Green
242f72ddab same vh protocol list: convert to dll_wss 2018-09-30 07:15:20 +08:00
Andy Green
93f4fe5532 lws_return_http_status: use /error.css if possible 2018-09-17 07:26:08 +08:00
Andy Green
fd810f198a http proxy: client: unix socket support
This allows the client stuff to understand that addresses beginning with '+'
represent unix sockets.

If the first character after the '+' is '@', it understands that the '@'
should be read as '\0', in order to use Linux "abstract namespace"
sockets.

Further the lws_parse_uri() helper is extended to understand the convention
that an address starting with + is a unix socket, and treats the socket
path as delimited by ':', eg

http://+/var/run/mysocket:/my/path

HTTP Proxy is updated to allow mounts to these unix socket paths.

Proxy connections go out on h1, but are dynamically translated to h1 or h2
on the incoming side.

Proxy usage of libhubbub is separated out... LWS_WITH_HTTP_PROXY is on by
default, and LWS_WITH_HUBBUB is off by default.
2018-09-12 13:58:13 +08:00
Chengsheng Shen
d8cf6e72ee roles: update ./lib/roles/README.md context.x path 2018-09-11 18:27:59 +08:00
Andy Green
78e6d45f78 openssl: error handling align 2018-09-11 18:27:59 +08:00
Andy Green
ebed5e74cb threadpool 2018-09-11 18:27:59 +08:00
Andy Green
edd7efd43d client: libuv: fix close handling during redirect
During client redirect we "reset" the wsi to the redirect address,
involving closing the current fd that was told to redirect (it will
usually be a completely different server or port).

With libuv and its two-stage close that's not trivial.  This solves
the problem we will "reset" (overwrite) where the handle lives in the
wsi with new a new connection / handle by having it copied out into
an allocated watcher struct, which is freed in the uv close callback.

To confirm it the minimal ws client example gets some new options, the
original problem was replicated with this

$ lws-minimal-ws-client-echo -s invalid.url.com -p 80

https://github.com/warmcat/libwebsockets/issues/1390
2018-09-11 18:27:59 +08:00
Andy Green
1665df4642 log client IP of well-wishers
Although getting a million of these doesn't make any trouble for lws, the
source should be logged.
2018-09-11 18:27:59 +08:00
Andy Green
fff8daa898 ws role: wsi ws may not have been allocated by time of close 2018-09-11 18:27:59 +08:00
Andy Green
b31f8b2aa6 ws role: use protocol bind and unbind and transition earlier
Now individual role callbacks are added in an earlier patch for protocol
bind and unbind, change the ws upgrade action to use the generic protocol
bind and unbind apis so the corresponding callbacks are issued for ws.
2018-09-11 18:27:59 +08:00
Martin Milata
43d0ab02e2 Ignore unknown headers in multipart file upload
https://github.com/warmcat/libwebsockets/pull/1385
2018-09-11 18:27:59 +08:00
Andy Green
f6a3aa01c9 http: enlarge headers buffers since they may meet large headers from vhost config 2018-09-11 18:27:59 +08:00
Andy Green
844b779130 lejp-conf: allow header value part to exceed one string chunk 2018-09-11 18:27:59 +08:00
Andy Green
e618ce1d4c h2: use vhost headers with tolower adaptation
h2 was not applying vhost headers, make it do so.

Also adapt any header names to lower-case as required by h2.
2018-09-11 18:27:59 +08:00
Andy Green
a27dfb2a3e clean: coverity 2018-09-11 18:27:59 +08:00
Andy Green
253942ca80 clean: solve type conversion warnings for appveyor 2018-09-11 18:27:59 +08:00
Andy Green
d1f9f0ae2d libwebsockets.h: split out into a dir of sub-includes included by libwebsockets.h
This has no effect on user code or backward compatibility.

It moves the in-tree public api header libwebsockets.h from ./lib
to ./include, and introduces a dir ./include/libwebsockets/

The single public api header is split out into 31 sub-headers
in ./include/libwebsockets.  ./include/libwebsockets.h contains
some core types and platform adaptation code, but the rest of it
is now 31 #include <libwebsockets/...>

At install time, /usr/[local/]include/libwebsockets.h is installed
as before, along now with the 31 sub-headers in ...include/libwebsockets/

There's no net effect on user code.

But the api header is now much easier to maintain and study, with 31
topic-based sub headers.
2018-09-11 18:27:59 +08:00
Andy Green
d58828692e http: compression methods
Add generic http compression layer eanbled at cmake with LWS_WITH_HTTP_STREAM_COMPRESSION.

This is wholly a feature of the HTTP role (used by h1 and h2 roles) and doesn't exist
outside that context.

Currently provides 'deflate' and 'br' compression methods for server side only.

'br' requires also -DLWS_WITH_HTTP_BROTLI=1 at cmake and the brotli libraries (available in
your distro already) and dev package.

Other compression methods can be added nicely using an ops struct.

The built-in file serving stuff will use this is the client says he can handle it, and the
mimetype of the file either starts with "text/" (html and css etc) or is the mimetype of
Javascript.

zlib allocates quite a bit while in use, it seems to be around 256KiB per stream.  So this
is only useful on relatively strong servers with lots of memory.  However for some usecases
where you are serving a lot of css and js assets, it's a nice help.

The patch performs special treatment for http/1.1 pipelining, since the compression is
performed on the fly the compressed content-length is not known until the end.  So for h1
only, chunked transfer-encoding is automatically added so pipelining can continue of the
connection.

For h2 the chunking is neither supported nor required, so it "just works".

User code can also request to add a compression transform before the reply headers were
sent using the new api

LWS_VISIBLE int
lws_http_compression_apply(struct lws *wsi, const char *name,
			   unsigned char **p, unsigned char *end, char decomp);

... this allows transparent compression of dynamically generated HTTP.  The requested
compression (eg, "deflate") is only applied if the client headers indicated it was
supported, otherwise it's a NOP.

Name may be NULL in which case the first compression method in the internal table at
stream.c that is mentioned as acceptable by the client will be used.

NOTE: the compression translation, same as h2 support, relies on the user code using
LWS_WRITE_HTTP and then LWS_WRITE_HTTP_FINAL on the last part written.  The internal
lws fileserving code already does this.
2018-09-02 14:43:05 +08:00
Andy Green
90e6e65bff partial: replace ad-hoc code with a wsi buflist_out
Various kinds of input stashing were replaced with a single buflist before
v3.0... this patch replaces the partial send arrangements with its own buflist
in the same way.

Buflists as the name says are growable lists of allocations in a linked-list
that take care of book-keeping what's added and removed (even if what is
removed is less than the current buffer on the list).

The immediate result is that we no longer have to freak out if we had a partial
buffered and new output is coming... we can just pile it on the end of the
buflist and keep draining the front of it.

Likewise we no longer need to be rabid about reporting multiple attempts to
send stuff without going back to the event loop, although not doing that
will introduce inefficiencies we don't have to term it "illegal" any more.

Since buflists have proven reliable on the input side and the logic for dealing
with truncated "non-network events" was already there this internal-only change
should be relatively self-contained.
2018-08-20 12:02:26 +08:00
Andy Green
5c0b0450f2 client: bind and drop protocol like server
HTTP server protocols have had for a while LWS_CALLBACK_HTTP_DROP/BIND_PROTOCOL
callbacks that mark when a wsi is attched to a protocol and detached.

It turns out this is generally useful for everything to know when a wsi is
joining a protocol and definitively completely finished with a protocol.

Particularly with client wsi where you provided the userdata externally, this
makes a clear point to free() it on the protocol binding being dropped.

This patch adds protocol bind / unbind callbacks to the role definition and
lets them operate on all roles.  For the various roles

HTTP server: LWS_CALLBACK_HTTP_BIND/DROP_PROTOCOL as before
HTTP client: LWS_CALLBACK_CLIENT_HTTP_BIND/DROP_PROTOCOL
ws server:   LWS_CALLBACK_WS_SERVER_BIND/DROP_PROTOCOL
ws client:   LWS_CALLBACK_WS_CLIENT_BIND/DROP_PROTOCOL
raw file:    LWS_CALLBACK_RAW_FILE_BIND/DROP_PROTOCOL
raw skt:     LWS_CALLBACK_RAW_SKT_BIND/DROP_PROTOCOL
2018-08-18 14:11:29 +08:00
Andy Green
d461f46a97 libwebsockets.h: clean out some boilerplate better put in core/private.h
https://github.com/warmcat/libwebsockets/issues/1370
2018-08-16 19:10:32 +08:00