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

102 commits

Author SHA1 Message Date
Loïc Hoguin
d52e84bdd9
Add shutdown_reason Websocket command
This allows changing the normal exit reason of Websocket
processes, providing a way to signal other processes of
why the exit occurred.
2019-10-10 11:33:35 +02:00
Loïc Hoguin
2e8fcb9a9e
Add cowboy_req:cast/2
Better than sending messages manually.
2019-10-07 13:25:49 +02:00
Loïc Hoguin
3977f2b96f
Document the commands based Websocket interface
The old interface with ok|reply|stop tuples is deprecated.
2019-10-06 16:51:27 +02:00
Loïc Hoguin
3e23aff1d1
Add Websocket option validate_utf8
This allows disabling the UTF-8 validation check
for text and close frames.
2019-10-05 17:32:50 +02:00
Loïc Hoguin
03dac1486d
Add cowboy_req:filter_cookies/2 2019-10-05 11:23:57 +02:00
Loïc Hoguin
5ffb4f98e0
Make cowboy_compress_h add vary: accept-encoding 2019-10-04 13:32:35 +02:00
Loïc Hoguin
28aee1f272
Document media type wildcard in content_types_accepted 2019-10-03 16:20:29 +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
eaa052616f
Ensure we can stream the response body from any process 2019-10-02 20:30:32 +02:00
Loïc Hoguin
20660d7566
Ensure we can read the request body from any process 2019-10-02 19:12:05 +02:00
Loïc Hoguin
f673e191b3
Add {set_options, #{metrics_user_data := Map}}
This allows giving custom metadata to the metrics stream handler.
This can be useful to for example provide the name of the
module handling the request which is only known after routing.
But any user data is allowed.

When called multiple times the user data maps are merged.
2019-10-02 15:23:23 +02:00
Loïc Hoguin
49af57d546
Implement backpressure on cowboy_req:stream_body
This should limit the amount of memory that Cowboy is using
when a handler is sending data much faster than the network.

The new max_stream_buffer_size is a soft limit and only has
an effect when the cowboy_stream_h handler is used.
2019-09-14 18:21:05 +02:00
Loïc Hoguin
42eb6bae69
Fix using custom fields in Req 2019-09-06 12:25:02 +02:00
Tony Han
7708fc77cd
Data received after RST_STREAM counts toward window 2019-07-16 15:32:58 +02:00
Loïc Hoguin
0223f69fcd
Move the final old HTTP suite tests and remove it 2018-11-22 00:12:18 +01:00
Loïc Hoguin
037b286aa8
Move many old HTTP test cases to the rest_handler test suite
A bug was fixed in cowboy_rest where when content_types_provided
returned a media type with a wildcard as first in the list, and
a request comes in without an accept header, then the media_type
value in the Req object would contain '*' instead of [] for the
parameters.
2018-11-21 18:39:59 +01:00
Loïc Hoguin
6058800abb
Move another test from the old HTTP test suite 2018-11-21 10:47:31 +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
f5015cb14b
Add the set_options Websocket command
It allows overriding the idle_timeout option only for now.
2018-11-16 13:49:00 +01:00
Loïc Hoguin
75045637fc
Ensure unknown options are ignored in set_options command 2018-11-16 13:09:01 +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
240da3f2d9
Add the set_options stream handler command
The first two options to benefit from this are the
cowboy_compress_h options.
2018-11-15 18:53:42 +01:00
Loïc Hoguin
fbfec873f6
Add a compress_buffering option to cowboy_compress_h
Also changes the behavior to disable buffering by default, so
that the default works in all cases, including server-sent events.
2018-11-15 10:11:36 +01:00
Loïc Hoguin
292039362a
Don't send the content-length header in empty 304 responses
It's OK to send it when set explicitly, as it can be set
to what the representation's size would have been.
2018-11-14 19:24:39 +01:00
Loïc Hoguin
4fedb33631
Ignore the boundary parameter when accepting multipart 2018-11-14 18:04:32 +01:00
Loïc Hoguin
8d920f3db9
Add the {deflate, boolean()} Websocket command
It allows to temporarily disable Websocket compression
when it was negotiated. It's ignored otherwise. This
can be used as fine-grained control when some frames
do not compress well.
2018-11-13 15:55:09 +01:00
Loïc Hoguin
8164b50453
Add deflate options for Websocket compression
They allow the server to configure what it is willing to accept
for both the negotiated configuration (takeover and window bits)
and the other zlib options (level, mem_level and strategy).

This can be used to reduce the memory and/or CPU footprint of
the compressed data, which comes with a cost in compression ratio.
2018-11-12 18:12:44 +01:00
Loïc Hoguin
7840f6db7b
Add ProvideRangeCallback tests using sendfile
And fix this case when multiple ranges are requested.
2018-11-11 16:09:28 +01:00
Loïc Hoguin
dd0fbab6b7
Add automatic ranged request handling for bytes units
Returning the atom auto instead of a callback informs Cowboy
that it needs to handle range requests automatically. This
changes the behavior so that the ProvideCallback function
is called and then Cowboy splits the data on its own and
sends the response without any other user involvement other
than defining the ranges_provided/2 callback.

This is a quick and dirty way to add range request support
to resources, and will be good enough for many cases including
for cowboy_static as it also works when the normal response
body is a sendfile tuple.
2018-11-11 13:57:26 +01:00
Loïc Hoguin
d7b7580b39
Add sendfile support to cowboy_req:stream_body
It is now possible to stream one or more sendfile tuples.
A simple example of what can now be done would be for
example to build a tar file on the fly using the sendfile
syscall for sending the files, or to support Range requests
with more than one range with the sendfile syscall.

When using cowboy_compress_h unfortunately we have to read
the file in order to send it. More options will be added
at a later time to make sure users don't read too much
into memory. This is a new feature however so existing
code is not affected.

Also rework cowboy_http's data sending to be flatter.
2018-11-09 17:42:37 +01:00
Loïc Hoguin
29043aa7b4
Add support for range requests (RFC7233) in cowboy_rest
This is currently undocumented but is planned to be documented
in the next version.
2018-11-07 18:55:06 +01:00
Loïc Hoguin
805a156785
Test stop against all relevant REST callbacks 2018-11-05 10:30:26 +01:00
Loïc Hoguin
06f9f3714f
Test switch_handler against all relevant REST callbacks 2018-11-05 10:01:51 +01:00
Loïc Hoguin
8c9ad7bf07
Add the rate_limited/2 REST callback 2018-11-04 11:58:59 +01:00
Loïc Hoguin
e0b036fe68
Add tests for charsets_provided
Fix cases where the q-value is 0 and where a wildcard
was sent in the accept-charset header.

Also don't send a charset in the content-type of the
response if the media type is not text.

Thanks to Philip Witty for help figuring this out.
2018-11-02 13:54:19 +01:00
Loïc Hoguin
399b6a16b4
Better handle content negotiation when accept contains charsets
Thanks to Philip Witty for help figuring this out.
2018-11-02 13:49:54 +01:00
Loïc Hoguin
b3bfcf068c
Add a cowboy_rest test for malformed if-*-match headers 2018-10-31 22:41:59 +01:00
Steve Domin
09bf1199aa
Add compress_threshold protocol option
Currently the compression threshold is set to 300 and hardcoded in the
codebase. There are cases where it make sense to allow this to be
configured, for instance when you want to enforce all responses to be
compressed regarldess of their size.
2018-10-31 17:05:11 +01:00
Grigory Starinkin
5ab5615ff0
Handle error_response command in cowboy_metrics_h 2018-10-31 15:13:23 +01:00
Loïc Hoguin
a8335c63df
Always dialyze tests and fix some cowboy_req specs 2018-10-31 10:50:57 +01:00
Loïc Hoguin
f810d8dd64
Add the {active, boolean()} Websocket command
This command is currently not documented. It allows disabling
the reading of incoming data from the socket, and can be used
as a poor man's flow control.
2018-09-21 15:01:57 +02:00
Loïc Hoguin
b56a5a1d60
Do not send a 101 after a final response in switch_protocol 2018-09-12 16:16:29 +02:00
Loïc Hoguin
8404b1c908
Add a commands-based interface to Websocket handlers
This feature is currently experimental. It will become the
preferred way to use Websocket handlers once it becomes
documented.

A commands-based interface enables adding commands without
having to change the interface much. It mirrors the interface
of stream handlers or gen_statem. It will enable adding
commands that have been needed for some time but were not
implemented for fear of making the interface too complex.
2018-09-11 14:33:58 +02:00
Loïc Hoguin
4b385749f2
Add cowboy_req:read_and_match_urlencoded_body/2,3 2018-09-07 13:56:12 +02:00
Loïc Hoguin
0a5fadc60b
Improve errors for when the ProvideCallback is missing 2018-08-13 17:23:48 +02:00
Loïc Hoguin
0fb68ec07f
Add test cases for cowboy_req:stream_events 2018-06-27 13:40:11 +02:00
Eric Meadows-Jönsson
f08f4610a0
Add streaming without chunking for HTTP/1.1
If content-length is set in the response headers
we can skip chunked transfer-encoding.
2018-06-25 11:44:38 +02:00
Loïc Hoguin
5229d790fb
Don't send transfer-encoding when streaming 204 responses 2018-05-18 18:38:26 +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
Loïc Hoguin
4d5174632c
Add initial support for system messages in cowboy_loop 2018-03-23 18:33:16 +01:00