0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 12:20:24 +00:00
Commit graph

2120 commits

Author SHA1 Message Date
Loïc Hoguin
1a175e7b56
Fix wrong HTTP/1 timeout being used in some cases
Added many tests to ensure the right timeout is picked in
the appropriate situation. Should there be any issues
remaining we can add more tests.
2024-01-15 15:18:40 +01:00
Loïc Hoguin
906a7ffc3c
Better error message when trying to reply twice
Also crash if trying to push after a reply was sent.
2024-01-09 13:06:11 +01:00
Loïc Hoguin
f0101ffe41
Shorten the 204/304 error message 2024-01-09 11:01:39 +01:00
Loïc Hoguin
a40bab8fb3
Improve the error when trying to send a 204/304 with a body 2024-01-09 10:59:40 +01:00
Loïc Hoguin
e4a78aaeb1
Document body reading in auto mode
It is now tested both via cowboy_req:read_body and
via cowboy_req:cast.

Removes a bad example from the guide of body reading
with period of infinity, which does not work.
2024-01-08 15:13:18 +01:00
Loïc Hoguin
c1490d7d55
Ensure HTTP/1.1 Websocket resets the trap_exit flag
While we are identified as a supervisor in the tree,
we no longer manage children processes at that point,
so do not need to trap exit signals. Users can still
enable trap_exit if they prefer to.
2024-01-08 11:47:59 +01:00
Loïc Hoguin
9784179498
Always add vary: accept-encoding in cowboy_compress_h
We must add it even if we don't end up compressing because
it indicates that we might. This indication doesn't mean
that the user agent's accept-encoding values will ever
result in content encoding being applied.
2024-01-08 10:22:24 +01:00
Loïc Hoguin
e0adf0a19c
Don't fail actions if master cache doesn't exist 2024-01-08 09:54:34 +01:00
Loïc Hoguin
6ef79ae410
Reject HTTP/1 requests with both content-length and transfer-encoding
The previous behavior was to accept them and drop the
content-length header as per the RFC recommendation.
But since this behavior is not normal it is safer to
just reject such requests than risk security issues.
2024-01-05 16:32:59 +01:00
Loïc Hoguin
5b2f600036
Don't automatically compress when response has etag
In the cowboy_compress_h stream handler.

Otherwise this could cause issues with caching, with the
etag being the same for compressed/uncompressed content.

Users that wish to send etags AND compress will have to
do it manually for the time being.
2024-01-05 15:53:42 +01:00
Loïc Hoguin
67df6fedae
Add cowboy:get_env/2,3 2024-01-05 12:31:48 +01:00
Loïc Hoguin
8f49f8792a
Fix Dialyzer warnings caused by my decompress changes 2024-01-05 12:31:19 +01:00
Loïc Hoguin
fd9711d949
Rework and improve the decompress stream handler
The read buffer was changed into an iovec to avoid doing
too many binary concatenations and allocations.

Decompression happens transparently: when decoding gzip,
the content-encoding header is removed (we only decode
when "gzip" is the only encoding so nothing remains).

We always add a content_decoded key to the Req object.
This key contains a list of codings that were decoded,
in the reverse order in which they were. Currently it
can only be empty or contain <<"gzip">> but future
improvements or user handlers may see it contain more
values.

The option to disable decompression was renamed to
decompress_enabled and defaults to true.

It is no longer possible to enable/disable decompression
in the middle of reading the body: this ensures that the
data we pass forward is always valid.

Various smaller improvements were made to the code,
tests and manual pages.
2024-01-04 15:50:12 +01:00
jdamanalo
3ed1b24dd6
Add cowboy_decompress_h stream handler 2023-12-21 15:39:08 +01:00
Loïc Hoguin
ffbcdf534c
Don't update an HTTP/2 stream's window if stream stopped 2023-12-21 15:38:51 +01:00
Nelson Vides
5ef64557b5
Exit gracefully on {error,closed} when reading the PROXY header
LH: Simplified the test a little.
2023-12-21 15:01:33 +01:00
Robert J. Macomber
f74b69c3ed
Optionally reset the idle timeout when sending data
A new option reset_idle_timeout_on_send has been added.
When set to 'true', the idle timeout is reset not only
when data is received, but also when data is sent.

This allows sending large responses without having to
worry about timeouts triggering.

The default is currently unchanged but might change in
a future release.

LH: Greatly reworked the implementation so that the
    timeout gets reset on almost all socket writes.
	This essentially completely supersets the original
	work. Tests are mostly the same although I
	refactored a bit to avoid test code duplication.

This commit also changes HTTP/2 behavior a little when
data is received: Cowboy will not attempt to update the
window before running stream handler commands to avoid
sending WINDOW_UPDATE frames twice. Now it has some
small heuristic to ensure they can only be sent once
at most.
2023-12-21 14:03:07 +01:00
Viktor Söderqvist
7400b04b02
Remove next_protocols_advertised 2023-12-19 11:57:54 +01:00
Loïc Hoguin
8fdb74a510
Shave off a few more seconds from rfc7540_SUITE 2023-12-19 11:09:54 +01:00
Loïc Hoguin
627a4508b5
Explicitly close the socket in some tests for speed ups
The socket staying open meant that the graceful shut down
of the Cowboy listeners were waiting for the connections
to be closed gracefully (or a timeout). Closing explicitly
where it makes sense ensures we don't unnecessarily wait.

This commit removes a full minute in the run time of all
Cowboy test suites (minus examples).
2023-12-18 18:17:09 +01:00
Dmitri Vereshchagin
2558ba65ad
Fix shutdown for HTTP/1.1 pipeline
Sending extra response prevented by terminating all streams except
the one currently executing.

LH: Reworded some variables to make what happens more obvious.
2023-12-18 15:39:39 +01:00
Loïc Hoguin
03a3bf4474
Delete the master cache on cron 2023-12-18 11:42:52 +01:00
Boris Pozdnyakov
e200272178
Reject invalid Connection header
LH: Small tweaks and added an HTTP/1.0 test.
2023-12-15 17:12:37 +01:00
Loïc Hoguin
1547e9b93e
Increase loop_handler_timeout timeouts
It seems that macOS GH runners don't do timeouts well.
2023-12-15 16:22:06 +01:00
jdamanalo
a81dc8af9d
Add timeout to cowboy_loop
LH: I have added a test that does both hibernate and timeout
    and fixed a related issue. I also tweaked the docs and tests.
2023-12-15 15:37:34 +01:00
Loïc Hoguin
a72bf4105f
Fix static_handler suite code path
A future OTP release will use 'strict' code path by default.
This change ensures it works both for old and new OTP.
2023-12-15 10:35:37 +01:00
Loïc Hoguin
67bd791dcc
Change send_timeout_close test to accomodate macOS 2023-12-14 15:25:25 +01:00
Loïc Hoguin
efb681d749
Handle socket errors in HTTP/1.1 and HTTP/2
Doing so will let us notice when the connection is gone instead
of waiting for timeouts, at least in the cases where the remote
socket was closed properly. Timeouts are still needed in case
of TCP half-open problems.

This change means that the order of stream handler commands is
more important than before because socket errors may occur
during the processing of commands.
2023-12-12 15:05:33 +01:00
Sergei Shuvatov
3f5f326b73
Add test for send_timeout_close
LH: I reworked the test a little and added the same test
for HTTP/2 so that both HTTP/1.1 and HTTP/2 get the issue
fixed.
2023-12-12 15:05:01 +01:00
Loïc Hoguin
0ce9696e5e
Note that we won't implement the HTTP/2 PRIORITY mechanism 2023-12-07 16:45:30 +01:00
Loïc Hoguin
6bc6100bbd
Fix position of rate_limited/2 callback in REST workflow guide 2023-12-07 16:11:50 +01:00
lin
4f26d6a573
Add UTF-8 support to example file_server
LH: I have fixed issues in the PR and incorporated changes
from a sister PR by @djankovic (git author: Dom J). I also
made sure the UTF-8 files were readable without Chinese
fonts and added their downloading to the examples test suite.
2023-12-07 15:31:11 +01:00
Loïc Hoguin
32594a5199
Fix Websocket subprotocol example 2023-12-07 14:17:13 +01:00
Anatolii Kosorukov
4907734a83
Fix echo_post example
Fix input parameter of `cowboy_req:reply` function.
2023-12-07 13:16:09 +01:00
Kian-Meng, Ang
b12b4300ba
Fix typos in documentation 2023-12-06 18:46:56 +01:00
Maria Scott
a93ac120f4
Remove official IRC channel 2023-12-06 12:46:40 +01:00
Viktor Söderqvist
42d87dd776
Add 'max_cancel_stream_rate' config for the rapid reset attack
Co-authored-by: Björn Svensson <bjorn.a.svensson@est.tech>
2023-12-06 12:41:58 +01:00
Loïc Hoguin
879a6b8bc5
Remove unneeded Makefile variables 2023-12-04 11:11:54 +01:00
Loïc Hoguin
ca6477af7b
Use init_per_suite instead of all/0 for init in tracer_SUITE 2023-12-01 15:46:23 +01:00
Loïc Hoguin
521266326d
Don't dialyze the tests by default 2023-12-01 11:08:01 +01:00
Loïc Hoguin
deb2ec3931
Reduce CT logs size in a couple test cases 2023-12-01 10:45:41 +01:00
Loïc Hoguin
d64ac25e92
Use GitHub actions for testing Cowboy
Now tested against OTP-24+.
Erlang.mk has been updated as well.
2023-12-01 10:00:33 +01:00
Loïc Hoguin
b2a16a2ee6
Don't force verify client cert in tests
This makes req_SUITE's cert_undefined test work again.
2023-11-23 15:09:06 +01:00
Loïc Hoguin
22adc4de51
Fix Ranch link in user guide 2023-05-02 11:20:02 +02:00
Loïc Hoguin
9e600f6c1d
Cowboy 2.10.0 2023-04-28 10:41:18 +02:00
Loïc Hoguin
326939c8a8
We are not using erl_make_certs anymore 2023-03-30 16:38:08 +02:00
Loïc Hoguin
8093d716fa
Fix tests with serialised maps
The key order of serialised maps changed in OTP-26.
2023-03-30 15:39:13 +02:00
Loïc Hoguin
12108ab668
Fix TLS tests for OTP-26+
ct_helper now uses the test certificates generated by
public_key. A few adjustments had to be made as a result.
2023-03-30 15:38:29 +02:00
Loïc Hoguin
251e70b219
Fix OTP-26+ warnings in test suites 2023-03-30 10:35:08 +02:00
Loïc Hoguin
4958af5745
Update Cowlib to 2.12.1 2023-03-29 15:20:48 +02:00