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

55 commits

Author SHA1 Message Date
Loïc Hoguin
eef66e0928
Remove copyright years from all files except LICENSE 2025-02-17 15:00:02 +01:00
Loïc Hoguin
053e233c56
Provide better control over which HTTP protocols are enabled
Over cleartext TCP the `protocols` option lists the enabled
protocols. The default is to allow both HTTP/1.1 and HTTP/2.

Over TLS the default protocol to use when ALPN is not used
can now be configured via the `alpn_default_protocol` option.

Performing an HTTP/1.1 upgrade to HTTP/2 over TLS is now
rejected with an error as connecting to HTTP/2 over TLS
requires the use of ALPN (or that HTTP/2 be the default
when connecting over TLS).
2025-02-10 15:26:00 +01:00
Loïc Hoguin
8cb9d242b0
Initial HTTP/3 implementation
This includes Websocket over HTTP/3.

Since quicer, which provides the QUIC implementation,
is a NIF, Cowboy cannot depend directly on it. In order
to enable QUIC and HTTP/3, users have to set the
COWBOY_QUICER environment variable:

  export COWBOY_QUICER=1

In order to run the test suites, the same must be done
for Gun:

  export GUN_QUICER=1

HTTP/3 support is currently not available on Windows
due to compilation issues of quicer which have yet to
be looked at or resolved.

HTTP/3 support is also unavailable on the upcoming
OTP-27 due to compilation errors in quicer dependencies.
Once resolved HTTP/3 should work on OTP-27.

Because of how QUIC currently works, it's possible
that streams that get reset after sending a response
do not receive that response. The test suite was
modified to accomodate for that. A future extension
to QUIC will allow us to gracefully reset streams.

This also updates Erlang.mk.
2024-03-26 15:53:48 +01:00
Loïc Hoguin
b36f064a91
Refresh copyright lines 2024-01-25 11:22: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
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
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
b9d4e05be0
Fix tests for OTP-25+ 2023-03-29 15:17:09 +02: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
47ecfd7318
Add a test confirming push requests have no body 2020-02-05 18:06:00 +01:00
Loïc Hoguin
63b17e4edf
Use /long_polling for rfc7540 tests that reset the stream 2019-10-10 17:06:59 +02:00
Loïc Hoguin
57badc9082
Add HTTP/2 tests with responses with HTTP/1.1 specific headers 2019-10-03 11:56:57 +02:00
Loïc Hoguin
ab44985a9e
Fix HTTP/2 CVEs
A number of HTTP/2 CVEs were documented recently:

  https://www.kb.cert.org/vuls/id/605641/

This commit, along with a few changes and additions in Cowlib,
fix or improve protection against all of them.

For CVE-2019-9511, also known as Data Dribble, the new option
stream_window_data_threshold can be used to control how little
the DATA frames that Cowboy sends can get.

For CVE-2019-9516, also known as 0-Length Headers Leak, Cowboy
will now simply reject streams containing 0-length header names.

For CVE-2019-9517, also known as Internal Data Buffering, the
backpressure changes were already pretty good at preventing this
issue, but a new option max_connection_buffer_size was added for
even better control over how much memory we are willing to allocate.

For CVE-2019-9512, also known as Ping Flood; CVE-2019-9515, also
known as Settings Flood; CVE-2019-9518, also known as Empty Frame
Flooding; and similar undocumented scenarios, a frame rate limiting
mechanism was added. By default Cowboy will now allow 1000 frames
every 10 seconds. This can be configured via max_received_frame_rate.

For CVE-2019-9514, also known as Reset Flood, another rate limiting
mechanism was added and can be configured via max_reset_stream_rate.
By default Cowboy will do up to 10 stream resets every 10 seconds.

Finally, nothing was done for CVE-2019-9513, also known as Resource
Loop, because Cowboy does not currently implement the HTTP/2
priority mechanism (in parts because these issues were well known
from the start).

Tests were added for all cases except Internal Data Buffering,
which I'm not sure how to test, and Resource Loop, which is not
currently relevant.
2019-10-02 10:44:45 +02:00
Loïc Hoguin
48f417ac8f
Fix and optimize sending of WINDOW_UPDATE frames
For long-running connections it was possible for the connection
window to become larger than allowed by the protocol because the
window increases claimed by stream handlers were never reclaimed
even if no data was consumed.

The new code applies heuristics to fix this and reduce the number
of WINDOW_UPDATE frames that are sent. It includes six new options
to control that behavior: margin, max and threshold for both the
connection and stream windows. The margin is some extra space
added on top of the requested read size. The max is the maximum
window size at any given time. The threshold is a minimum window
size that must be reached before we even consider sending more
WINDOW_UPDATE frames. We also avoid sending WINDOW_UPDATE frames
when there is already enough space in the window, or when the
read size is 0.

Cowlib is set to master until a new tag is done.
2019-09-05 14:07:38 +02:00
Tony Han
22cc88bae4
Add a zero-length DATA frame in the lingering_data test 2019-07-26 10:05:30 +02:00
Tony Han
7708fc77cd
Data received after RST_STREAM counts toward window 2019-07-16 15:32:58 +02:00
Fredrik Enestad
7ff9e963b8
Fallback to host header if authority is missing 2019-04-01 15:04:33 +02:00
Loïc Hoguin
d2f367fba3
Use try..after in tests that start their own listeners 2018-11-19 09:29:21 +01:00
Loïc Hoguin
bed328b6c9
Use ?FUNCTION_NAME instead of ct_helper:name()
Cowboy is 19+ so it's OK to use it.
2018-11-19 09:05:34 +01:00
Loïc Hoguin
633aa89f00
Fix intermittent test failures in rfc7540_SUITE 2018-05-22 13:05:15 +02:00
Loïc Hoguin
dc58eea9b4
Ensure tests in rfc7540_SUITE can be repeated 2018-05-22 13:04:42 +02:00
Loïc Hoguin
ae6c787062
Honor the SETTINGS_ENABLE_PUSH from clients
This fixes curl when fetching resources that use push.
2018-05-16 11:00:25 +02:00
Loïc Hoguin
3ebd01805f
Fix some intermittent test issues in rfc7540 2018-04-30 14:23:38 +02:00
Loïc Hoguin
7d4791b32c
Fix some rfc7540 tests that had an empty :path 2018-04-30 13:48:34 +02:00
Loïc Hoguin
8d1f468ac0
Reject HTTP/2 requests with a body size different than content-length 2018-04-30 13:47:33 +02:00
Loïc Hoguin
17349fafc2
Add tests for rejecting streams depending on themselves 2018-04-29 20:32:36 +02:00
Loïc Hoguin
84b4128d06
Receive and ignore HTTP/2 request trailers if any
This is a first step toward properly supporting request trailers.
2018-04-29 17:39:48 +02:00
Loïc Hoguin
2db5ffbf84
Add SETTINGS ack timeout and option settings_timeout 2018-04-28 11:00:50 +02:00
Loïc Hoguin
add71bfb7e
Fix intermittent test failures for rfc7540 2018-04-28 00:53:12 +02:00
Loïc Hoguin
5d5a00c863
Fix an rfc7540 test to have a different error reason 2018-04-27 20:19:02 +02:00
Loïc Hoguin
9a29aea148
Add options controlling maximum h2 frame sizes 2018-04-27 17:58:37 +02:00
Loïc Hoguin
d38d86c4a9
Add options controlling initial control flow windows 2018-04-26 22:08:05 +02:00
Loïc Hoguin
7373822b86
Add the max_concurrent_streams h2 option 2018-04-25 21:32:58 +02:00
Loïc Hoguin
8f4adf437c
Add options to control h2's SETTINGS_HEADER_TABLE_SIZE 2018-04-25 16:55:52 +02:00
Loïc Hoguin
8b9a09c9fe
HTTP/2 informational responses don't end the stream 2018-04-23 15:49:34 +02:00
Loïc Hoguin
19054e40e0
Fix crash in cowboy_http2 when content-length is invalid 2018-02-28 16:18:29 +01:00
Loïc Hoguin
bec9a43d50
Fix a broken test case in the rfc7540 suite 2017-11-29 17:52:09 +01:00
Loïc Hoguin
bd6c32d3b7
Fix an intermittent test failure in the rfc7540 suite 2017-11-29 17:17:22 +01:00
Loïc Hoguin
cf3ab5832a
Add nowarn_export_all to all test suites 2017-11-29 16:57:10 +01:00
Loïc Hoguin
73126e7693
Add many rfc7540 tests, improve detection of malformed requests 2017-11-29 14:54:47 +01:00
Loïc Hoguin
4cdd1aa70e
Add more flow control tests to rfc7540 and fix related issues 2017-11-27 22:49:50 +01:00
Loïc Hoguin
7f80ff28a5
Add more rfc7540 tests along with their respective fixes 2017-11-27 19:00:35 +01:00
Loïc Hoguin
bc82679330
Fix a few rfc7540 tests
Cowboy takes a few shortcuts to avoid wasting resources when
there is a protocol error. The RFC wants us to send a different
error depending on the state of the stream at the time of the
error, and for us to maintain the connection in cases where we
would have to spend valuable resources to decode headers. In
all these cases Cowboy will simply close the connection with
an appropriate error.
2017-11-27 13:42:04 +01:00
Loïc Hoguin
e7114577bb
Fix a bug in HTTP/2 where connection gets closed prematurely
When the user code was sending a response fully without reading
the request body, the connection could get closed when receiving
DATA frames for that body. We now ask the client to stop sending
data via a NO_ERROR RST_STREAM, and linger any stream that has
been reset so that we can skip any pending frames from that
stream.

This fixes a number of intermittent failures in req_SUITE, which
now passes reliably.

In addition a small number of rfc7540_SUITE test cases have been
corrected as they were incorrect.
2017-10-23 14:49:33 +01:00
Loïc Hoguin
9ef4536656
Add many tests for RFC7540 5.1 and 5.1.1 and related fixes 2017-05-23 14:09:38 +02:00
Loïc Hoguin
0d81dc04f1
Add more HTTP/2 tests for RFC7540 4.1 and 4.3 2017-03-02 19:35:24 +01:00
Loïc Hoguin
bb83a6ce33
Unknown HTTP/2 frames are ignored 2017-02-26 13:24:15 +01:00
Loïc Hoguin
a3636adcac
Add many test cases covering RFC7540 4.2
These tests cover frame sizes. It's mostly edge cases for sure
(ie misbehaving clients and us having to reject them properly).
I had these almost ready for a long time, so I'm glad I can
push them out.

This requires updating Cowlib too (we currently track master).
2017-02-25 20:05:31 +01:00
Loïc Hoguin
43adacc760
Welcome to 2017 2017-01-02 19:36:36 +01:00