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

614 commits

Author SHA1 Message Date
Loïc Hoguin
920adb9b82
Fix an intermittent test failure 2024-01-16 11:21:30 +01:00
geeksilva97
308045fd67
Reject responses with explicit set-cookie header
LH: The tests received a lot of fixes and tweaking.
    I also reworded the error message to be more concise.
2024-01-15 17:43:14 +01:00
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
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
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
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
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
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
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
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
Kian-Meng, Ang
b12b4300ba
Fix typos in documentation 2023-12-06 18:46:56 +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
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
deb2ec3931
Reduce CT logs size in a couple test cases 2023-12-01 10:45:41 +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
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
Loïc Hoguin
b9d4e05be0
Fix tests for OTP-25+ 2023-03-29 15:17:09 +02:00
Loïc Hoguin
30ee75cea1
Update Erlang.mk 2022-09-19 14:17:37 +02:00
Martin Björklund
8795233c57
AcceptCallback may now return created/see_other tuples for POST
They replace and deprecate the {true,URI} return value.
2020-11-27 16:17:43 +01:00
Viktor Söderqvist
059d58d39f
Graceful shutdown
Note: This commit makes cowboy depend on cowlib master.

Graceful shutdown for HTTP/2:

1. A GOAWAY frame with the last stream id set to 2^31-1 is sent and a
   timer is started (goaway_initial_timeout, default 1000ms), to wait
   for any in-flight requests sent by the client, and the status is set
   to 'closing_initiated'. If the client responds with GOAWAY and closes
   the connection, we're done.
2. A second GOAWAY frame is sent with the actual last stream id and the
   status is set to 'closing'. If no streams exist, the connection
   terminates. Otherwise a second timer (goaway_complete_timeout,
   default 3000ms) is started, to wait for the streams to complete. New
   streams are not accepted when status is 'closing'.
3. If all streams haven't completed after the second timeout, the
   connection is forcefully terminated.

Graceful shutdown for HTTP/1.x:

1. If a request is currently being handled, it is waited for and the
   response is sent back to the client with the header "Connection:
   close". Then, the connection is closed.
2. If the current request handler is not finished within the time
   configured in transport option 'shutdown' (default 5000ms), the
   connection process is killed by its supervisor (ranch).

Implemented for HTTP/1.x and HTTP/2 in the following scenarios:

* When receiving exit signal 'shutdown' from the supervisor (e.g. when
  cowboy:stop_listener/3 is called).
* When a connection process is requested to terminate using
  sys:terminate/2,3.

LH: Edited tests a bit and added todos for useful tests to add.
2020-11-27 15:38:21 +01:00
Loïc Hoguin
fa9c8ad832
Use gun:ws_send/3 in tests 2020-11-23 11:02:01 +01:00
Loïc Hoguin
03d306e6d1
Fix concurrent body streaming getting stuck with HTTP/2 2020-07-03 11:02:59 +02:00
Loïc Hoguin
39b2816255
204 and 304 responses must not include a body
When calling cowboy_req:reply/4 with a body a crash will occur
resulting in a 500 response. When calling cowboy_req:stream_reply/2,3
and then attempting to send a body a crash will occur.
2020-05-20 13:41:05 +02:00
Loïc Hoguin
8337aca4d3
Increase the default max_keepalive HTTP option to 1000
100 is very low for current deployments. 1000 is more
appropriate as a default value.
2020-05-20 11:08:58 +02:00
Loïc Hoguin
4edc39b003
Don't stop listeners that don't exist in static_handler_SUITE 2020-05-20 11:08:24 +02:00
Loïc Hoguin
0d0e7d164c
Increase the timetrap timeout in req_SUITE on Windows
Still seeing intermittent failures on Windows due to
timetrap so let's see if doubling the timeout again helps.
2020-04-08 10:28:27 +02:00
Loïc Hoguin
f79d60e0c7
Get rid of timeouts in metrics_SUITE
Again to avoid intermittent issues.
2020-04-08 10:28:11 +02:00
Loïc Hoguin
b339713461
Allow {error, enotconn} as test success in security_SUITE
This happens from time to time on Windows and is partially
due to how the test is written.
2020-04-07 10:18:29 +02:00
Loïc Hoguin
e51ac66728
Rely on timetrap timeouts for tracer_SUITE 2020-04-06 20:14:31 +02:00
Loïc Hoguin
8cba8c3c68
NO_PARALLEL=1 will disable (most) parallel testing
This is to make up for very slow or low resource environments,
like the FreeBSD CI environment currently.
2020-04-06 16:39:28 +02:00