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

401 commits

Author SHA1 Message Date
Andy Green
d618ee8761 docs: improve explanation in LWS_CALLBACK_RECEIVE_CLIENT_HTTP
https://github.com/warmcat/libwebsockets/issues/1772
2019-11-26 17:47:57 +00:00
Andy Green
0f7f27801e http redirect: 303: force method to GET
This teaches http client stuff how to handle 303 redirects... these
can happen after POST where the server side wants you to come back with
a GET to the Location: mentioned.

lws client will follow the redirect and force GET, this works for both
h1 and h2.  Client protocol handler has to act differently if it finds
it is connecting for the initial POST or the subsequent GET, it can
find out which by checking a new api lws_http_is_redirected_to_get(wsi)
which returns nonzero if in GET mode.

Minimal example for server form-post has a new --303 switch to enable
this behaviour there and the client post example has additions to
check lws_http_is_redirected_to_get().
2019-11-17 10:47:01 +00:00
Andy Green
285fb9c8ba server vfs: close: cleanup also at just_kill_connection
Also make sure to close the vfs handle on transaction completed as
well as close.
2019-11-16 09:00:15 +00:00
Zhiwen Zheng
34eca205e5 acme: add wildcard support to CSR 2019-11-06 16:02:36 +00:00
Andy Green
0ab4a707fb format strings: ban %.*s as some platforms lack it
The %.*s is very handy to print strings where you have a length, but
there is no NUL termination.  It's quite widely supported but at least
one vendor RTOS toolchain doesn't have it.

Since there aren't that many uses of it yet, audit all uses and
convert to a new helper lws_strnncpy() which uses the smaller of
two lengths.
2019-11-04 13:49:14 +00:00
Andy Green
e1cf534775 jwk: add export option to suppress final CRLF
https://github.com/warmcat/libwebsockets/issues/1746

Adding the final CRLF is a NOP at JSON level, but can disrupt hashing the
JSON if it isn't expecting it.

Add flags to the jwk export so it can be controlled... operation remains
unchanged for old values 0 and 1 but a second flag can be OR-ed to control
issue of final CRLF.
2019-11-04 13:49:13 +00:00
Andy Green
ce55c5dfe4 lwsac: fix header split optimization 2019-11-02 18:34:05 +00:00
Sun Dro
10bb008dd4 lws_get_tsi
Get thread service index wsi belong to
2019-10-29 09:14:42 +00:00
Andy Green
2f4316527b sul: more paranoid casting vs libc header types
As it is, if time_t is 32-bit on the platform it might lead to
arithmetic overflow, so force it to lws_usec_t (uint64_t) even
though it works OK here on x86_64.

Add a minimal example aimed at testing the wsi hrtimer stability
consistently across platforms.

Add and disable by default hrtimer dump code (this is too expensive
and specific to internal testing to leave in for debug mode even if
it's not printed).  If you hack it enabled, it will dump the sul
list for the pt and assert if the list is disordered.
2019-10-27 06:22:13 +00:00
Maciek Sipior
7d8036b72e humanize: export schema arrays to include lengths
Due to windows compiler choking on it otherwise
2019-10-23 13:08:56 +01:00
Kristján Valur Jónsson
afb7b30f0d windows: LWS_EXTERN must be 'extern' if not building DLL
if it is simply empty, header declarations of externally defined arrays will fail.
2019-10-23 06:33:22 +01:00
Andy Green
df2c2fa291 lws_system: client cert 2019-10-22 13:46:29 +01:00
Andy Green
ebdc0ad084 lwsac-backfill
Optimizations for memory-tight systems.

Check all previous gaps first for any usage, so gaps we created when
faced with perhaps a relatively large allocation that left a lot of
the last chunk on the table can be backfilled with smaller things as
it goes on.

Separate the members that only live in the head object out of the
buffer management object, reducing the cost of new chunks.  Allocate
the head object members as the first thing in the first chunk, and
adjust all the code to look there for them.
2019-10-17 09:19:57 +01:00
Andy Green
c776ac50d6 lwsac: add blob deduplication helper
Add lwsac helper api to allow user code to perform constant string folding
easily within an lwsac.  After isolating a string or blob that it wants to store in
the lwsac and point to, it can check if the string or blob already exists earlier
in the lwsac first, and if so just point to that without copying it in again.

For some formats with repeated strings like JSON, the saving can add up to
something useful.
2019-10-17 09:19:57 +01:00
Andy Green
938f692c48 adopt: improve logging of server adopt fail
This is usually something that either couldn't negotate tls at all
or compatible tls parameters.

Log the vhost it came in on and the IP.
2019-10-14 07:08:57 +01:00
Andy Green
300e22c815 lws_system: auth token handling using buflist 2019-10-12 12:41:14 +01:00
Andy Green
f9e9977534 lws_buflist: extra apis for in-place use 2019-10-12 12:41:14 +01:00
Andy Green
37ac955fc4 wsi flags: extra encodings 2019-10-12 12:41:14 +01:00
Andy Green
d0fa39af7f lws_system: dhcpclient
Generic lws_system IPv4 DHCP client

 - netif and route control via lib/plat apis
 - linux plat pieces implemented
 - Uses raw ip socket for UDP broadcast and rx
 - security-aware
 - usual stuff plus up to 4 x dns server

If it's enabled for build, it holds the system
state at DHCP until at least one registered interface
has acquired a set of IP / mask / router / DNS server

It uses PF_PACKET which is Linux-only atm.  But those
areas are isolated into plat code.

TODOs

 - lease timing and reacquire
 - plat pieces for other than Linux
2019-10-12 12:41:14 +01:00
Andy Green
127e53cf98 client: multipart mime generation helpers
lws has been able to generate client multipart mime as shown
in minimal-http-client-post, but it requires a lot of user
boilerplate to handle the boundary, related transaction header,
and multipart headers.

This patch adds a client creation flag to indicate it will
carry multipart mime, which autocreates the boundary string
and applies the transaction header with it, and an api to
form the boundary headers between the different mime parts
and the terminating boundary.
2019-10-12 12:41:14 +01:00
Andy Green
3c95483518 adopt: udp iface and AF_PACKET 2019-10-12 12:41:14 +01:00
Andy Green
a83c6439e6 client h2: auth bearer option flag
This affects max header size since we use the latter half
of the pt_serv_buf to prepare the (possibly huge) auth token.

Adapt the pt_serv_buf_size in the hugeurl example.
2019-10-12 12:41:14 +01:00
Andy Green
07495c20c8 h2: overflow quirk
Some servers set the tx credit to the absolute max and then add to it... this is illegal
(and checked for in h2spec).  Add a quirk flag that works around it by reducing the
initial tx credit size by a factor of 16.
2019-10-12 12:41:14 +01:00
Andy Green
54573924ef lws_is_ssl: update docs 2019-10-12 12:41:14 +01:00
Andy Green
b40e19edca h2: end stream with end headers
This shouldn't be necessary; just END_HEADERS flag should be enough.
But nghttp2 will not talk to us unless we end the stream from our side.

Unfortunately ending the stream at the time we sent the headers means
we cannot support the long poll half-close scheme.  So add a quirk
flag to optionally support this behaviour of nghttp2 when the client
is creating the connection.
2019-10-12 12:41:14 +01:00
Andy Green
41b7716a52 lws_system: auth callback 2019-10-12 12:41:14 +01:00
Andy Green
f4b38f104c LWS_WITH_UDP 2019-10-12 12:41:14 +01:00
Andy Green
5013162b1e abstract: existing connection compare 2019-10-10 16:34:37 +01:00
Andy Green
fc295b7959 muxable client: make http support generic
h1 and h2 has a bunch of code supporting autobinding outgoing client connections
to be streams in, or queued as pipelined on, the same / existing single network
connection, if it's to the same endpoint.

Adapt this http-specific code and active connection tracking to be usable for
generic muxable protocols the same way.
2019-10-10 16:34:37 +01:00
Andy Green
dabd865a5c async-dns: update for lws_retry udp 2019-10-10 16:34:37 +01:00
Andy Green
04f99f1499 lws_retry: udp support 2019-10-10 16:34:37 +01:00
Andy Green
bb7f96d32b cmdline: introduce builtin switches
Rather than do all switches by hand on the minimal examples,
add a helper that knows some "builtin" ones like -d and
others to set context options you might want to use in
any example.
2019-10-10 16:34:37 +01:00
Andy Green
bce1f01370 lws_state and system state
Introduce a generic lws_state object with notification handlers
that may be registered in a chain.

Implement one of those in the context to manage the "system state".

Allow other pieces of lws and user code to register notification
handlers on a context list.  Handlers can object to or take over
responsibility to move forward and retry system state changes if
they know that some dependent action must succeed first.

For example if the system time is invalid, we cannot move on to
a state where anything can do tls until that has been corrected.
2019-09-22 09:35:07 -07:00
Andy Green
f9f6bb66fe lws_validity: unified connection validity tracking
Refactor everything around ping / pong handling in ws and h2, so there
is instead a protocol-independent validity lws_sul tracking how long it
has been since the last exchange that confirms the operation of the
network connection in both directions.

Clean out periodic role callback and replace the last two role users
with discrete lws_sul for each pt.
2019-09-22 09:35:07 -07:00
Jakob Szumacher
503bb8f8c9 client: LCCSCF_ALLOW_INSECURE
AG add options the minimal http client related to this
2019-09-22 09:35:07 -07:00
Andy Green
6cae9d3021 doxygen: cleanup and add recent includes 2019-09-22 09:35:07 -07:00
Andy Green
ba754c4cb2 h2: unify immortal stream tracking across SSE and ws substreams
It was already correct but add helpers to isolate and deduplicate
processing adding and closing a generically immortal stream.

Change the default 31s h2 network connection timeout to be settable
by .keepalive_timeout if nonzero.

Add a public api allowing a client h2 stream to transition to
half-closed LOCAL (by sending a 0-byte DATA with END_STREAM) and
mark itself as immortal to create a read-only long-poll stream
if the server allows it.

Add a vhost server option flag LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL
which allows the vhost to treat half-closed remotes as immortal long
poll streams.
2019-09-22 03:08:36 -07:00
Andy Green
4e8497b28a context-vhost options: move to uint64_t 2019-09-22 03:08:36 -07:00
Andy Green
d42f434a77 lws_sul: make it clear NULL no longer valid in lws_service_fd 2019-09-22 03:08:36 -07:00
Andy Green
78c7b0651e buflist: add static reason logging to internal aware apis 2019-09-22 03:08:36 -07:00
Andy Green
d808748cd6 detailed latency stats
Remove LWS_LATENCY.

Add the option LWS_WITH_DETAILED_LATENCY, allowing lws to collect very detailed
information on every read and write, and allow the user code to provide
a callback to process events.
2019-09-22 03:06:59 -07:00
Andy Green
c591e1adfc asynchronous dns for ipv4 and ipv6
This adds the option to have lws do its own dns resolution on
the event loop, without blocking.  Existing implementations get
the name resolution done by the libc, which is blocking.  In
the case you are opening client connections but need to carefully
manage latency, another connection opening and doing the name
resolution becomes a big problem.

Currently it supports

 - ipv4 / A records
 - ipv6 / AAAA records
 - ipv4-over-ipv6 ::ffff:1.2.3.4 A record promotion for ipv6
 - only one server supported over UDP :53
 - nameserver discovery on linux, windows, freertos

It also has some nice advantages

 - lws-style paranoid response parsing
 - random unique tid generation to increase difficulty of poisoning
 - it's really integrated with the lws event loop, it does not spawn
   threads or use the libc resolver, and of course no blocking at all
 - platform-specific server address capturing (from /etc/resolv.conf
   on linux, windows apis on windows)
 - it has LRU caching
 - piggybacking (multiple requests before the first completes go on
   a list on the first request, not spawn multiple requests)
 - observes TTL in cache
 - TTL and timeout use lws_sul timers on the event loop
 - ipv6 pieces only built if cmake LWS_IPV6 enabled
2019-09-19 06:54:53 +01:00
Andy Green
8b37f98feb tokenize: flag for # as rest of line comment
Add a flag for tokenizing config where # indicates
the rest of the line is a comment (eg, /etc/resolv.conf)
2019-09-16 11:09:05 +01:00
Andy Green
35b23c3996 network: ipv4 and 6 aware helpers
Add helpers to parse and print ipv4 and ipv6 numeric addresses
in all the canonical formats.

Expose internal lws_sockaddr46 union and add helper wrappers
to directly operate on sa46.
2019-09-15 11:04:16 +01:00
Andy Green
5f238ed86d unaligned serialization and deserialization helpers
u16, u32 and u64 read and write, plus VBI read and write for up to
64bit / 10 bytes, all to and from uint8_t.
2019-09-06 15:30:51 +01:00
Andy Green
3cbeef5d26 lws_tls_client_vhost_extra_cert_mem 2019-09-06 15:30:51 +01:00
Andy Green
adb6379df0 base64: stateful decode 2019-09-06 15:30:51 +01:00
Andy Green
61b5a37a3a lws_retry: use base ms number and set jitter percentage 2019-09-06 15:30:51 +01:00
Andy Green
0fa5563d18 freertos: rename esp32 plat to freertos 2019-08-26 09:58:57 +01:00
Andy Green
2a98642cff c++: establish a single place for opaque forward references 2019-08-18 05:40:56 +01:00