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

1091 commits

Author SHA1 Message Date
Jeffrey Griffin
6460e9d2d2
Fix infinite loop on incomplete multipart body
I have amended a lot of changes from the original commit
to make it behave as expected, including returning a 400
error. LH
2017-10-02 13:28:43 +02:00
Loïc Hoguin
292e732abf
Fix the documentation for the command flow 2017-10-02 10:46:45 +02:00
Loïc Hoguin
fda2d150db
Fix error response when constraint validation fails 2017-09-27 16:20:38 +02:00
Loïc Hoguin
11ae407eed
Ensure the behavior on stream handler crash is consistent
Also corrects the lack of error response when HTTP/1.1 is used.
2017-09-27 14:17:27 +02:00
Loïc Hoguin
d47e22edaa
Cleanup various comments 2017-09-25 13:52:58 +02:00
Loïc Hoguin
ea80e7a309
Avoid some crashes when HTTP/2 streams flush their response 2017-09-25 12:55:30 +02:00
Loïc Hoguin
c09b10190b
Move body length count to cowboy_stream_h instead of protocols
The documentation was correct, the code was not.

This should make it easier to implement new protocols. Note that
for HTTP/2 we will need to add some form of counting later on to
check for malformed requests, but we can do simpler and just
reduce from the expected length and then check if that's 0 when
IsFin=fin.
2017-09-25 12:48:47 +02:00
Loïc Hoguin
a6126306a2
Centralize stream handler error reporting in cowboy_stream 2017-09-21 12:53:21 +02:00
Loïc Hoguin
1cc877b649
Fix propagating the stacktrace on errors for OTP 19 2017-09-14 18:23:55 +02:00
Loïc Hoguin
5027d1335d
Rework the proc_lib_hack
It is completely removed for connection processes, because
assuming Cowboy is written properly this should bring us
nothing anymore in 2.0.

It is reworked for request processes, there we want to
always propagate the stacktrace (including for exits)
because we will print a report to help with debugging
and proc_lib doesn't propagate it for exits.

At the same time the initial callback for connection
and request processes has been changed to connection_process
and request_process, which should help with identifying
processes when inspecting.
2017-09-14 15:34:37 +02:00
Loïc Hoguin
3cbf885961
Improve how we detect request errors
When the request process exits with a {request_error, Reason, Human}
exit reason, Cowboy will return a 400 status code instead of 500.
Cowboy may also return a more specific status code depending on
the error. Currently it may also return 408 or 413.

This should prove to be more solid that looking inside the stack
trace.
2017-09-14 13:42:17 +02:00
Loïc Hoguin
2376983295
Remove transfer-encoding parsing from cowboy_req
The header never reaches this point.
2017-09-05 13:25:06 +02:00
Loïc Hoguin
d1c210b105
Remove an unused variable 2017-09-05 13:24:46 +02:00
Loïc Hoguin
4fd6e2f7cd
Accept sendfile tuple with 0 length in cowboy_req
This will result in no data being sent. It's simply easier to
do this than to have to handle 0 size cases in user code.
2017-09-04 20:48:07 +02:00
Loïc Hoguin
58e9e76814
Fix more documentation todos
I have decided not to include a manual page for
cowboy_stream_h at this point because it clashes
with the cowboy_stream manual page. This decision
will be revisited in the future.
2017-09-04 14:33:44 +02:00
Loïc Hoguin
9a1810bf13
Tentative fix for out of order queued data 2017-08-21 16:55:30 +02:00
Loïc Hoguin
daef32d907
Properly clean up timers when terminating 2017-08-21 14:40:01 +02:00
Loïc Hoguin
c0ec1ad4a9
Add missing cowboy_children module
My bad! Still new at this.
2017-08-08 21:39:23 +02:00
Loïc Hoguin
45ddcd8c67
Implement the shutdown timeout for request processes
This should work very similar to normal supervisors,
in particular during the shutdown sequence when the
connection process goes down or switches to Websocket.

Processes that need to enforce the shutdown timeout
will be required to trap exits, just like in a supervisor.
In a vanilla Cowboy, this only matters at connection
shutdown, as Cowboy will otherwise wait for the request
process to be down before stopping the stream.

Tests are currently missing.
2017-08-08 16:59:33 +02:00
Loïc Hoguin
4fa7aeb0fd
Fix HTTP/2 server push
Cowboy was encoding the headers then decoding them when initializing
the request. The problem is that the encoding and decoding contexts
are not the same. Now, Cowboy will directly use the headers it
received in the push command for the new request. This is also
more efficient.

I am surprised it worked at all considering the issue.
2017-07-26 17:36:41 +02:00
Steven Magelowitz
7eb0072b06
Req Body length can be a non_neg_integer or infinity 2017-07-15 10:42:48 +02:00
Loïc Hoguin
ff3915a243
Catch more 400 errors 2017-07-12 19:20:31 +02:00
Loïc Hoguin
5a272e4fbe
Aggregate validation errors and pass them in exception 2017-07-01 16:40:30 +02:00
Loïc Hoguin
09506e7b5f
Fix wrong percent encoding in a router test 2017-06-28 18:59:20 +02:00
Loïc Hoguin
eb1a06cf5d
Remove the cyrillic latin1 test
These characters are not allowed in URI paths.
2017-06-28 18:57:51 +02:00
Loïc Hoguin
12b5e78aaa
Fix unit tests in cowboy_router following interface changes 2017-06-28 18:57:04 +02:00
Loïc Hoguin
c221730371
Improve the interface for constraints
There are two important changes in this commit.

Constraints are now producing an error tuple. This error tuple
in turn can be provided to a function for formatting a human
readable error message. Both the error tuple and the formatting
code are controlled by and part of the constraint function.

Constraints now also implement the reverse operation.
When constraint functions only validate, the reverse operation
will be the same as the forward operation. When they also do
some conversion then the reverse operation will reverse it.

Since constraints are now performing 3 different operations
(forward, reverse and format_error), they now take the form
of a function accepting two separate arguments. The operation
is the first argument.

In addition, the return value was changed to take the form
of {ok, Value} | {error, Reason}. The value must be returned
as-is if it was not modified.
2017-06-28 17:38:17 +02:00
Loïc Hoguin
ec00e3d60e
Make cowboy_req:read_part return multipart headers as map 2017-06-09 16:57:11 +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
767da623f1
Fix terminate not being called on connection close in HTTP/1.1
Introduces the new stream_handler_SUITE test suite. More cases
will be added later on.
2017-06-02 12:31:00 +02:00
Loïc Hoguin
cbf7972f10
Don't terminate streams that were already terminated
This and the issues in the last two commits were reported
by leo2007 on IRC.
2017-05-31 13:20:12 +02:00
Loïc Hoguin
cad3e3f63d
Fix bad accounting of HTTP/2 windows
The previous code was incorrectly substracting the maximum
frame size we could send when the data we were actually sending
was much lower.
2017-05-31 12:49:21 +02:00
Loïc Hoguin
18e2d684b3
Apply the received SETTINGS frame 2017-05-31 12:48:22 +02:00
Loïc Hoguin
5f421f93bc
Introduce the req_filter Websocket option
This option allows customizing the compacting of the Req object
when using Websocket. By default it will keep most public fields
excluding headers of course, since those can be large.
2017-05-28 20:19:39 +02: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
f3e5f3e410
Preliminary h2 flow control support
Existing tests pass. A number of things remain to be done.
Has only been tested with Gun so far. Feedback welcome!
2017-05-19 20:18:00 +02:00
Alexandre Snarskii
304e3efbf8
make set_env working with maps. 2017-05-07 18:39:47 +02:00
Steven Magelowitz
f302ce2b83
length can be a non_neg_integer or infinity 2017-05-05 17:55:18 +02:00
Loïc Hoguin
96bbf6752f
Properly handle 101 upgrade responses for Websocket 2017-05-05 16:10:15 +02:00
Loïc Hoguin
7db724f04a
Add inactivity_timeout and other options improvements 2017-05-05 13:48:25 +02:00
Loïc Hoguin
6100470c90
Kill all children processes when terminating the connection
This is a more or less temporary solution to an existing problem.
In the future we will need to enforce a shutdown timeout for
these processes.
2017-05-03 18:31:28 +02:00
Loïc Hoguin
95d2855f62
Add the idle_timeout HTTP/1.1 protocol option
This fixes the connection being dropped because of request_timeout
despite there being some active streams.
2017-05-03 17:44:00 +02:00
Loïc Hoguin
b403f26da6
Remove an outdated todo comment 2017-04-18 16:36:03 +02:00
Loïc Hoguin
b7210d6d1a
Get rid of stray messages when killing HTTP/2 request processes 2017-04-18 16:33:41 +02:00
Loïc Hoguin
061cc227b1
Make the default 204 response go through stream handlers 2017-04-18 16:07:01 +02:00
Loïc Hoguin
6e8b907ae2
Pass the HTTP/2 switch_protocol event to stream handlers
To accomplish this the code for sending the 101 response was
moved to the cowboy_http2 module.
2017-04-18 14:06:34 +02:00
Loïc Hoguin
10dfd8c910
Add the early_error cowboy_stream callback
This callback is called when an error occurs before the request
(including headers, excluding body) was fully received. The
init/3 callback will not be called. The callback receives the
partial Req object (possibly empty), the reason for the error
and the response command that the server will send. It allows
you to be aware of the error and possibly modify the response
before it is sent.
2017-03-27 10:26:13 +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