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

548 commits

Author SHA1 Message Date
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
1af508c4cd
Add more rfc7230 tests and improve transfer-encoding
It's worth noting that transfer-encoding now takes precedence
over content-length as recommended by the RFC, so that when
both headers are sent we only care about transfer-encoding
and explicitly remove content-length from the headers.
2017-11-20 21:12:05 +01:00
Loïc Hoguin
3da9a6eef9
Add a test for early errors that occur on the request-line 2017-11-20 16:26:37 +01:00
Loïc Hoguin
92672b49af
Queue HTTP/2 trailers when there's still data in the buffer 2017-11-20 15:46:23 +01:00
Loïc Hoguin
9969684035
Improve trailers test when no te header is sent 2017-11-20 12:17:44 +01:00
Loïc Hoguin
62bf505d33
Add more rfc7230 tests
Also fixes the handling of the max_headers option for HTTP/1.1.
It is now a strict limit and not dependent on whether data is
already in the buffer.
2017-11-20 00:23:27 +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
8be803cb07
The static suite's large file is not created on Windows 2017-11-19 16:13: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
aedd274e26
Disable the tracer suite when compiled natively 2017-11-17 22:55:56 +01:00
Loïc Hoguin
ce5ab4b49a
Initialize trace patterns only once
They are global for the node for all future call trace flags,
so it's not necessary to set them repeatedly with every request.

Doing it once at startup also ensures we can't have race
conditions when the user wants to change which trace patterns
should be used (because requests are concurrent and patterns
end up overwriting themselves repeatedly), and makes this
changing of trace patterns much more straightforward: the
user can just define the ones they want. The default function
traces everything.

In addition I have also added the tracer_flags option to make
the trace flags configurable, excluding the tracer pid.
2017-11-17 13:23:38 +01:00
Loïc Hoguin
39baed6c80
Add preliminary support for trailers in responses
This depends on changes in Cowlib that are only available on
master.
2017-11-15 14:58:49 +01:00
Loïc Hoguin
6cc162583d
Keep the state returned by the tracer callback
It was mistakenly discarded.
2017-11-10 14:59:11 +00:00
Loïc Hoguin
da304799fe
Add a terminate event to the tracer and more tests 2017-11-03 17:52:18 +00:00
Loïc Hoguin
af58babd94
Fix stream_handler_SUITE test failures 2017-11-01 19:24:42 +00:00
Loïc Hoguin
5bb6438e10
Don't crash when cowboy_clock is not running
This can happen normally when Cowboy is restarted, for example.
Instead of failing requests when that happens, we degrade
gracefully and do a little more work to provide the current
date header.
2017-11-01 17:06:37 +00:00
Loïc Hoguin
836342abb8
Add {switch_handler, Module} return value to cowboy_rest
Also {switch_handler, Module, Opts}.

Allows switching to a different handler type. This is
particularly useful for processing most of the request
with cowboy_rest and then streaming the response body
using cowboy_loop.
2017-11-01 16:27:26 +00:00
Loïc Hoguin
83bd8bc935
Fix two edge cases for cowboy_req:stream_body
Sending data of size 0 with the fin flag set resulted in nothing
being sent to the client and still considering the response to
be finished for HTTP/1.1.

For both HTTP/1.1 and HTTP/2, the final chunk of body that is
sent automatically by Cowboy at the end of a response that the
user did not properly terminate was not passing through stream
handlers. This resulted in issues like compression being incorrect.

Some tests still fail under 20.1.3. They are due to recent zlib
changes and should be fixed in a future patch release. Unfortunately
it does not seem to be any 20.1 version that is safe to use for
Cowboy, although some will work better than others.
2017-11-01 15:33:10 +00:00
Loïc Hoguin
ad9ab51648
Add some todos 2017-10-31 17:15:11 +00:00
Loïc Hoguin
4e85ad76a0
Fix a unused warning 2017-10-31 16:50:17 +00:00
Loïc Hoguin
d41f2914b0
Fix broken tests in loop_handler_SUITE 2017-10-31 16:49:48 +00:00
Loïc Hoguin
fb13e5c9e9
Fix the static_handler test suite
Bad requests correctly return 400, not 500.
2017-10-31 15:41:25 +00:00
Loïc Hoguin
a97640d56d
Add informational responses to metrics 2017-10-31 15:04:00 +00:00
Loïc Hoguin
217fac7f44
Handle expect: 100-continue request headers
The 100 continue response will only be sent if the client
has not sent the body yet (at all), if the connection is
HTTP/1.1 or above and if the user has not sent it yet.

The 100 continue response is sent when the user calls
read_body and it is cowboy_stream_h's responsibility
to send it. This means projects that don't use the
cowboy_stream_h stream handler will need to handle the
expect header themselves (but that's okay because they
might have different considerations than normal Cowboy).
2017-10-30 16:21:25 +00:00
Loïc Hoguin
f3d6b05b86
Add cowboy_req:inform/2,3
User code can now send as many 1xx responses as necessary.
2017-10-29 21:03:04 +00:00
Loïc Hoguin
f4331f7c16
Add cowboy_tracer_h stream handler
Another experimental stream handler. It enables tracing for
the connection process and any children processes based on
the matching of the request. It can be used to do ad-hoc
tracing by sending a specific header, path, method or other.

It is meant to be used both for tests and production. Some
configuration scenarios are NOT safe for production, beware.

It's important to understand that, at this time, tracing
is enabled on the scale of the entire connection including
any future request processes. Keep this in mind when trying
to use it in production. The only way to stop tracing is
by having the callback function exit (by calling exit/1
explicitly). This can be done after a certain number of
events for example. Tracing can generate a lot of events,
so it's a good idea to stop after a small number of events
(between 1000 and 10000 should be good) and to avoid tracing
the whole world.

Documentation will follow at a later time.
2017-10-27 17:18:28 +01:00
Loïc Hoguin
ef58e15547
Introduce cowboy_req:sock/1 and cowboy_req:cert/1
To obtain the local socket ip/port and the client TLS
certificate, respectively.
2017-10-25 21:03:26 +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
133d359674
Add a metrics test for switching to Websocket 2017-10-22 14:54:13 +01:00
Loïc Hoguin
4bebe39975
Ensure stream terminate is called when switching protocols 2017-10-22 14:53:04 +01:00
Loïc Hoguin
debaecd49a
Add a test for stream_reply metrics 2017-10-21 21:03:06 +01:00
Loïc Hoguin
c4651261b6
Add a test for early_error metrics 2017-10-21 14:56:28 +01:00
Loïc Hoguin
2a905e9bda
Add a metrics test when the handler didn't send anything
Also fix a test group to use h2 instead of HTTP/1.1.
2017-10-21 13:12:36 +01:00
Loïc Hoguin
1ef5a1c45b
Add a test for metrics with a request body 2017-10-20 18:00:40 +01:00
Loïc Hoguin
4211ea41bd
Add experimental metrics stream handler
It collects metrics and passes them to a configurable callback
once the stream terminates. It will be documented in a future
release. More tests incoming.
2017-10-20 14:46:10 +01:00
Loïc Hoguin
c602871f86
Fix HTTP/1.1 stopping streams too early
It is possible in some cases to move on to the next request
without waiting, but that can be done as an optimization
later on if necessary.
2017-10-20 13:16:04 +01:00
Loïc Hoguin
6fc05a6d64
Make sure a path parsing error in the router gives a 400 2017-10-03 00:30:15 +02:00
Loïc Hoguin
9317751cb3
Fix cowboy:set_env when the env value is missing 2017-10-02 16:19:13 +02:00
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
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
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
9f5a1803da
Add tests for direct Req access 2017-09-05 15:28:11 +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
0995fc99e0
Add a static handler test with an empty file 2017-09-04 18:00:56 +02:00
Loïc Hoguin
0828e0b9ce
Alphabetical order some tests 2017-09-04 15:48:46 +02:00