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

1125 commits

Author SHA1 Message Date
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
bdd324ec01
Fix unused type in cowboy_static 2018-11-05 17:33:00 +01:00
Loïc Hoguin
9d2b1a8892
Simplify the code that calls REST callbacks 2018-11-05 11:44:24 +01:00
Loïc Hoguin
8c9ad7bf07
Add the rate_limited/2 REST callback 2018-11-04 11:58:59 +01:00
Loïc Hoguin
be09711687
Add an option to disable sendfile for a listener 2018-11-03 18:55:40 +01:00
Loïc Hoguin
571719a164
Add a charset option to cowboy_static 2018-11-02 15:36:41 +01:00
Loïc Hoguin
f181e510b9
Remove the default charset iso-8859-1 in cowboy_rest
This requirement was removed in RFC7231 and the rationale
behind it was documented in RFC6657.
2018-11-02 14:01:29 +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
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
Loïc Hoguin
30e117a942
Make sure we don't send error_responses on the wrong stream 2018-10-31 15:35:49 +01:00
Grigory Starinkin
5ab5615ff0
Handle error_response command in cowboy_metrics_h 2018-10-31 15:13:23 +01:00
Loïc Hoguin
473e3fb82b
Improve a few types, including cowboy_req:req() 2018-10-31 14:11:45 +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
122faedc25
Initial support for the PROXY protocol header
Depend on Ranch master for now since it isn't in any release yet.
2018-10-30 23:30:54 +01:00
Loïc Hoguin
e11279e0d2
Remove a useless todo 2018-10-28 13:12:17 +01:00
Loïc Hoguin
a764075b89
Rename a few functions and shuffle arguments 2018-10-28 11:47:49 +01:00
Loïc Hoguin
266178b6bc
Remove an unnecessary function 2018-10-28 11:42:18 +01:00
Loïc Hoguin
d4129e6305
Exit gracefully on parent exit/sys:terminate/2,3 2018-10-28 10:20:43 +01:00
Loïc Hoguin
21ff3ff256
Fix small issues introduced in the previous commit 2018-10-27 10:07:34 +02:00
Loïc Hoguin
f1018fd1c1
Use cow_http2_machine's timer handling 2018-10-27 00:16:13 +02:00
Loïc Hoguin
7d118b547f
Use cow_http2:parse_sequence/1 2018-10-26 18:51:49 +02:00
Loïc Hoguin
e1d970b5eb
Switch cowboy_http2 to the new cow_http2_machine
The new module is a merge of the Cowboy and Gun HTTP/2
state machines. Using a common code will help future
developments rather than duplicating the work.

A notable change is in how streams are terminated
when the handler stops before the body is sent. The
cowboy_stream:terminate function is now called only
after the body has been sent fully (or the stream
is reset in-between), not when the stop command is
returned. This will most likely have an impact on
metrics but will be closer to reality.

I had to comment a broken test in rfc7231_SUITE that
was cheating, cheating is no longer possible.

This depends on Cowlib master for the time being. A
new Cowlib version will be released once both Cowboy
and Gun are ported to use cow_http2_machine and I'm
satisfied with it.
2018-10-26 10:23:28 +02:00
Loïc Hoguin
3310849115
Simplify a case clause 2018-10-26 10:16:15 +02:00
Loïc Hoguin
d394eb7256
Fix ranch:start_tls when transport options are a map 2018-10-02 10:03:09 +02: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
06a3a93de0
Update Ranch to 1.6.1 2018-08-13 15:07:59 +02:00
Bing Han
e9fd2925ae
Fix cancelling undefined settings timer
when settings_timeout is infinity
2018-08-13 11:10:49 +02:00
Loïc Hoguin
4b65a307f8
Add missing log command to the commands() type 2018-08-06 13:31:44 +02:00
Loïc Hoguin
5bece31775
Add missing logger spec for cowboy_http2 opts 2018-07-09 10:08:48 +02:00
Loïc Hoguin
a76c32db5e
Introduce undocumented option logger
This commit reworks the logging that Cowboy does via
error_logger to make the module that will do the actual
logging configurable.

The logger module interface must be the same as logger
and lager: a separate function per log level with the
same log levels they support.

The default behavior remains to call error_logger,
although some messages were downgraded to warnings
instead of errors. Since error_logger only supports
three different log levels, some messages may get
downgraded/upgraded depending on what the original
log level was to make them compatible with error_logger.

The {log, Level, Format, Args} command was also
added to stream handlers. Stream handlers should
use this command to log messages because it allows
writing a stream handler to intercept some of those
messages and extract information or block them as
necessary.

The logger option only applies to Cowboy itself,
not to the messages Ranch logs, so more work remains
to be done in that area.
2018-06-28 17:10:18 +02:00
Loïc Hoguin
34f57ebbd3
Make sure cowboy_stream_h calls subsequent stream handlers 2018-06-27 18:07:58 +02:00
Loïc Hoguin
68ede9cfe4
Disable warnings for erlang:get_stacktrace/0 in OTP-21+ 2018-06-27 17:52:25 +02:00
Loïc Hoguin
5001fcbc34
Add missing frame types to websocket_handle specs/docs
Thanks Artem.
2018-06-26 10:59:22 +02:00
Loïc Hoguin
b2b5e3a01a
Add an undocumented stream_events function
I will test it on a private project before settling on it.
2018-06-25 15:56:29 +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
5d1cf36358
Remove the trailer header from HTTP/1.1 response if no TE 2018-05-18 18:38: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
763eef4e46
Do not process HTTP/1.1 requests coming in after the last 2018-05-18 17:10:54 +02:00
Loïc Hoguin
2f9ab91cdd
Add more validation of absolute-form request targets 2018-05-18 15:12:31 +02:00
Loïc Hoguin
fb5a261614
Move a router test from old_http_SUITE to cowboy_router 2018-05-17 17:53:16 +02:00
Loïc Hoguin
0e629f4799
Add option linger_timeout to cowboy_http 2018-05-16 16:01:30 +02:00
Loïc Hoguin
cc49659f93
Wrap the sendfile call in a try/catch for HTTP
This should reduce the amount of noise in RabbitMQ.
2018-05-16 12:28:23 +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
d732e74dd5
Use default port when not given in :authority 2018-05-16 10:42:25 +02:00