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

207 commits

Author SHA1 Message Date
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
0f257d06b6
Add hibernate option to cowboy_http and cowboy_http2
When enabled the connection process will automatically hibernate.
Because hibernation triggers GC, this can be used as a way to
keep memory usage lower, at the cost of performance.
2025-02-07 17:59:44 +01:00
Loïc Hoguin
8e121d138c
Fix request_timeout triggering when a request was in the buffer
The problem was that when a request immediately following another
request with a large enough body, the data for the new request
(including headers) would be buffered waiting for more data,
instead of being processed immediately. If no more data came
in on the socket the request_timeout would eventually trigger.
Now the buffer is processed immediately.
2025-02-06 12:18:59 +01:00
Björn Svensson
662f6af982
Correcting TransOpts in send_timeout_close tests 2025-01-23 13:29:47 +01:00
Loïc Hoguin
b36f064a91
Refresh copyright lines 2024-01-25 11:22:54 +01:00
Loïc Hoguin
e8b4715a9f
Reduce sleep in chunked_one_byte_at_a_time
To avoid having the connection get closed due to us taking
too long on unreliable environments like GitHub Actions.
2024-01-18 15:19:23 +01:00
Loïc Hoguin
ecf3d43613
Improve reliability of a few tests
GitHub Actions runners are not as good as self-hosted BuildKite
so some adjustments need to be made to timeouts and such.
2024-01-17 20:56:46 +01:00
Loïc Hoguin
920adb9b82
Fix an intermittent test failure 2024-01-16 11:21:30 +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
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
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
67bd791dcc
Change send_timeout_close test to accomodate macOS 2023-12-14 15:25:25 +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
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
cf84f59d9b
Add persistent_term support to the router 2019-09-28 15:40:41 +02:00
Loïc Hoguin
6f1a541fa2
Improve the reliability of some http_SUITE tests 2018-11-22 12:18:00 +01:00
Loïc Hoguin
dc240adc1e
Move some tests out of the old HTTP test suite
And additional minor tweaks.
2018-11-21 10:25:01 +01:00
Loïc Hoguin
1a1fb95f56
Fix the request_timeout_infinity test
Wrong option was being tested.
2018-11-20 13:26:02 +01:00
Loïc Hoguin
386df43ea4
Handle a test case sometimes sending a response too fast 2018-11-20 11:28:46 +01:00
Loïc Hoguin
ff674fe6e8
Wait for the connection to be up in a few tests 2018-11-20 11:28:25 +01: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
8d6d78575f
Add the chunked option for HTTP/1.1
It allows disabling the chunked transfer-encoding. It
can also be disabled on a per-request basis, although
it will be ignored for responses that are not streamed.
2018-11-18 13:25:12 +01:00
Loïc Hoguin
1949357f0c
Allow overriding cowboy_http's idle_timeout per request
This allows requests that expect to run longer to do so
without impacting the configuration of other requests.
2018-11-16 12:54:34 +01:00
Loïc Hoguin
6f57405b5c
Allow disabling keep-alive for HTTP/1.0 connections 2018-11-14 18:04:32 +01:00
Loïc Hoguin
3c8e6cf819
Use gun:info instead of hacks for test socket operations 2018-09-26 17:17:25 +02:00
Loïc Hoguin
f63609cb9c
Correct two tests that introspect the Gun state
It has changed in Gun 1.2.
2018-09-23 14:04:47 +02:00
Loïc Hoguin
ef426e0ff4
Fix the infinity timeout tests
Make sure the test fails when the code is incorrect.
2018-08-13 11:10:49 +02:00
Loïc Hoguin
0254c80c33
Move timeout tests from old_http_SUITE to http_SUITE
Also fix the idle_timeout test which was producing
an extra crash log.
2018-05-17 17:41:55 +02:00
Loïc Hoguin
5964273cc4
Fix the flushing of messages when switching to Websocket
We now flush messages that are specific to cowboy_http only.

Stream handlers should also flush their own specific messages
if necessary, although timeouts will be flushed regardless
of where they originate from.

Also renames the http_SUITE to old_http_SUITE to distinguish
new tests from old tests. Most old tests need to be removed
or converted eventually as they're legacy tests from Cowboy 1.0.
2018-03-26 18:53:07 +02:00
Bartek Walkowicz
2131709328
Add case for handling infinity for idle/request_timeout
Currently cowboy assumes that idle_timeout or request_timeout is
a number and always starts timers. Similar situation takes place
in case of preface_timeout for http2. This commit adds case for
handling infinity as a timeout, allowing to not start mentioned
timers.
2018-03-14 17:15:06 +01:00
Paul Fisher
82cd22a88b
Allow colon within path segments
Allow `cowboy_router:compile` to handle colon characters within
path segments, rather than exiting with `badarg`.  This is allowed
via RFC 7230 2.7 -> [RFC 3986 3.3](https://tools.ietf.org/html/rfc3986#section-3.3):

```
      segment       = *pchar
      segment-nz    = 1*pchar
      segment-nz-nc = 1*( unreserved / pct-encoded / sub-delims / "@" )
                    ; non-zero-length segment without any colon ":"

      pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
```
2018-01-16 11:24:49 +01:00
Loïc Hoguin
eafca21198
Fix HTTP/1.1 pipelining
Cases where a request body was involved could sometimes
fail depending on timing. Also fix all of the old
http_SUITE tests.
2017-12-12 11:37:48 +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
ce32e1985a
Add more tests to the rfc7230 suite
Found more bugs! Unfortunately no fix for them in this commit.
2017-11-24 00:16:19 +01:00
Loïc Hoguin
14173d5929
Move the pipeline test to the rfc7230 suite 2017-11-23 18:50:07 +01:00
Loïc Hoguin
c4e43ec26a
Add more rfc7230 tests and better handle bad chunk sizes
Bad chunk sizes used to be accepted and could result in
a badly parsed body or a timeout. They are now properly
rejected.

Chunk extensions now have a hard limit of 129 characters.
I haven't heard of anyone using them and Cowboy does not
provide an interface for them, but we can always increase
or make configurable if it ever becomes necessary (but
I honestly doubt it).

Also a test from the old http suite could be removed. Yay!
2017-11-22 23:10:00 +01:00
Loïc Hoguin
d7761b5259
Remove another test from the old http suite 2017-11-19 22:17:57 +01:00
Loïc Hoguin
f6539a9a68
Move tests from old http suite to rfc7230 suite 2017-11-19 22:04:48 +01:00
Loïc Hoguin
185d928e1a
Remove duplicate /echo/body_qs tests from the old suite 2017-11-18 00:19:01 +01:00
Loïc Hoguin
bfe7f82812
Remove duplicate static handler tests from the old suite 2017-11-17 23:57:32 +01:00
Loïc Hoguin
7d9f6611ae
Fix the remaining http_SUITE test cases 2017-07-14 19:09:42 +02:00
Loïc Hoguin
23fcfe9eea
Fix more of the older tests
The Cowboy behavior has changed a little and gives more
accurate error responses now. And in some cases, successes.
2017-07-13 00:20:56 +02:00
Loïc Hoguin
cf4d8166f8
Remove tests for set_resp_body with a stream fun 2017-07-12 19:25:56 +02:00
Loïc Hoguin
3c18585945
Remove any mention of the waiting_stream hack 2017-07-12 18:55:09 +02:00
Loïc Hoguin
acc5fed589
Remove the onresponse tests from http_SUITE 2017-07-12 18:36:49 +02:00
Loïc Hoguin
3eb7693e4f
Remove outdated multipart tests
They have equivalents in req_SUITE.
2017-06-28 13:07:44 +02:00
Loïc Hoguin
6f7b59886e
Remove NumAcceptors argument from start_clear/tls
They are now cowboy:start_clear/3 and cowboy:start_tls/3.
The NumAcceptors argument can be specified via the
num_acceptor transport option. Ranch has been updated
to 1.4.0 to that effect.
2017-06-07 15:15:54 +02:00
Loïc Hoguin
42c95b1584
Rewrite the tests for header name/value limits
Putting them in the correct test suite, with the proper
documentation etc.
2017-01-03 18:07:39 +01:00