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

652 commits

Author SHA1 Message Date
James Fish
c8242ab396 Add chunked response body fun
Adds a new type of streaming response fun. It can be set in a similar
way to a streaming body fun with known length:

Req2 = cowboy_req:set_resp_body_fun(chunked, StreamFun, Req)

The fun, StreamFun, should accept a fun as its single argument. This
fun, ChunkFun, is used to send chunks of iodata:

ok = ChunkFun(IoData)

ChunkFun should not be called with an empty binary or iolist as this
will cause HTTP 1.1 clients to believe the stream is over. The final (0
length) chunk will be sent automatically - even if it has already been
sent - assuming no exception is raised.

Also note that the connection will close after the last chunk for HTTP
1.0 clients.
2013-04-26 21:02:10 +01:00
Loïc Hoguin
e54149555e Move a test resource where it belongs 2013-04-26 17:34:24 +02:00
Loïc Hoguin
12bd1afeed Merge branch 'fix-tests' of git://github.com/fishcakez/cowboy 2013-04-26 15:28:41 +02:00
Loïc Hoguin
e73780975c Merge branch 'pr-381-fix' of git://github.com/seletskiy/cowboy 2013-04-26 13:45:47 +02:00
Seletskiy Stanislav
f316b47d13 Add default CTP: "text/html" maps to to_html 2013-04-26 18:34:01 +07:00
James Fish
77d1082233 Fix memory issue with large return values in testcases
Previously http_SUITE:echo_body/1 and http_SUITE:check_raw_status/1
returned large values. Common test would then try to write these to the
logs causing tests to take a long time and use lots of memory.
2013-04-26 02:08:50 +01:00
Loïc Hoguin
690927d9bd Update Autobahn test suite to 0.5.3 2013-04-24 21:48:24 +02:00
Loïc Hoguin
f329862384 Only test Websocket RFC6455 in Autobahn from now on 2013-04-24 20:33:51 +02:00
Loïc Hoguin
ad91aaf81a Reorganize the http test suite 2013-04-24 20:28:44 +02:00
Loïc Hoguin
282e532ba9 Move SSL test certificates in a subdirectory 2013-04-22 19:27:47 +02:00
Loïc Hoguin
2e91677723 Reorganize the websocket test suite
We now have the suite specific modules in the data folder.
Compilation is performed by the Makefile instead of ct_run.
2013-04-22 17:03:54 +02:00
Loïc Hoguin
b58a0549e1 Add default operations for OPTIONS method in REST
It defaults to setting the Allow header to "HEAD, GET, OPTIONS".
2013-04-12 19:02:00 +02:00
Loïc Hoguin
2aabc73045 Ensure we can fetch the body in the info/3 function of loop handlers 2013-04-12 14:32:37 +02:00
Vladimir Dronnikov
180143f9b2 rest: reject incorrect content-type header 2013-04-12 14:58:08 +04:00
Loïc Hoguin
5a171d0f80 Remove process_post, post_is_create, create_path, created_path callbacks
Instead it will always go through content_types_accepted and it is
up to the resource code to do any creation and to return the created
path if the method is POST and the client should be redirected to the
created resource's location.

This removes the meta value 'put_path' as it is not needed anymore.

This fixes an issue with PATCH where content types were not normalized.
2013-04-11 22:25:36 +02:00
rambocoder
84d7671e91 Check the length before reading the body in body/1 and body_qs/1 2013-03-06 08:50:45 -05:00
Slava Yurin
bb1362c744 Add '*' matcher for parameters
For get_type_provided:
'*' will be match any parameters of media-range in "accept" header.
If '*' matched, then '*' is replaced by the matching parameters.
If Accept header is missing and '*' using, then in media_type in parameters
will be '*' and reply content-type will be without any parameters.

For content_types_accepted:
'*' will be match any parameters in "content-type" header.
2013-03-03 22:54:37 +07:00
Loïc Hoguin
3442acbe35 Run tests in parallel 2013-03-02 16:24:34 +01:00
Loïc Hoguin
0ba06578f2 Use random ports for tests 2013-03-02 14:39:05 +01:00
Loïc Hoguin
b2ffff9bec Add cowboy:set_env/3 2013-02-20 12:14:21 +01:00
Loïc Hoguin
40b8d0befc Better handle socket closing with loop handlers
We now read from the socket to be able to detect errors or TCP close
events, and buffer the data if any. Once the data receive goes over
a certain limit, which defaults to 5000 bytes, we simply close the
connection with an {error, overflow} reason.
2013-02-11 09:03:13 +01:00
Loïc Hoguin
d9b3727a62 Merge branch 'patch-1' of https://github.com/CamShaft/cowboy
Conflicts:
	src/cowboy_rest.erl
2013-01-29 22:33:03 +01:00
Tom Burdick
8a798014e9 allow POST rest handling to specify path after accepting content 2013-01-29 13:12:53 -06:00
Loïc Hoguin
a59c5d6e91 Merge branch 'rest_patch' of https://github.com/treetopllc/cowboy 2013-01-29 19:16:45 +01:00
Loïc Hoguin
85d05fff34 Fix chunked streaming of request body and improve speed 2013-01-29 19:12:34 +01:00
Tom Burdick
c4d1ee5547 add patch support to cowboy_rest 2013-01-29 11:34:20 -06:00
Loïc Hoguin
a357c49d1b New routing
Ultimately few things change, it's mostly just a nicer syntax and
slightly different expectations. The name of the value `dispatch`
did not change, because the previous dispatch values will now fail
if the code is not updated to using `cowboy_router:compile/1`.

No constraints have been implemented in this commit.
2013-01-28 16:53:09 +01:00
Loïc Hoguin
3b8a1365d1 Do not require inets for running tests anymore 2013-01-22 14:22:28 +01:00
Loïc Hoguin
647e95aed1 Replace terminate/2 with terminate/3, adding a Reason
This should have been done a *long* time ago, back when I initially
added Websocket support. This is the first part of two in improving
loop handler support with regards to socket closure.

Reason may include: {normal, shutdown} for the most normal shutdown,
{normal, timeout} for a loop handler timeout shutdown, or {error, _}
if an error occured.
2013-01-22 02:34:18 +01:00
Loïc Hoguin
81cfc1651e Improve keepalive tests 2013-01-21 14:34:33 +01:00
Loïc Hoguin
823a82b8f2 Fix an issue for replies in onresponse mishandling headers
Reported and fixed over email by Adrian Roe.
2013-01-20 19:06:28 +01:00
Loïc Hoguin
82de4254dd Make cowboy_req:has_body/1 return boolean()
This makes it similar to the other has_* functions.
2013-01-19 17:20:35 +01:00
Loïc Hoguin
8d69099508 Improve websocket close handling
We now always send a failure reason (bad protocol, bad encoding, etc.)
unless the closure was initiated by the client and it didn't send a
close code.

We now check that the close frames have a payload that is valid UTF-8,
unless they don't have a payload at all.

We now do not crash the process anymore when bad opcodes are sent, or
when the opcode 0 is sent before fragmentation was initiated.

Overall this makes us closer to full compliance with the RFC.
2013-01-14 16:20:33 +01:00
Loïc Hoguin
5dd09737d0 Websocket text frames are now checked for UTF-8 correctness
The autobahntestsuite now passes 100% of the tests. We are
getting close to fully implementing the Websocket RFC.
2013-01-13 00:10:32 +01:00
Loïc Hoguin
71b68d53d9 All frames sent from client to server MUST be masked
Good in theory, but implementations may vary. If something stops
working after this commit we might need some tweaks to support
existing clients.

Please try it and give feedback.
2013-01-12 16:04:35 +01:00
Loïc Hoguin
10e3692fa6 Remove support for Websocket hixie76 draft
It was only used by Safari 5.0.1 and possibly 5.1. Their market share
is dropping as we speak. It was also insecure (disabled in Firefox
for that reason).

This will allow us to make much more efficient and cleaner code for
the rest of the Websocket versions we support (drafts 7 to 17 + RFC),
which are pretty much all versions seen in the wild excluding the
one we're removing here.
2013-01-10 21:58:38 +01:00
Loïc Hoguin
9bfef7c715 Update autobahntestsuite to 0.5.2
Also small mostly insignificant changes to tests.
2013-01-10 19:54:10 +01:00
Loïc Hoguin
01f57ad65d Add optional automatic response body compression
This behavior can be enabled with the `compress` protocol option.
See the `compress_response` example for more details.

All tests are now ran with and without compression for both HTTP
and HTTPS.
2013-01-07 22:42:16 +01:00
Loïc Hoguin
a013becc66 Add protection against slowloris vulnerability
This changes the behavior of the `timeout` protocol option to
mean "Time in which the full request line and headers must be
received". The default of 5s should be fine for all normal uses.

This change has no noticeable impact on performance and is thus
enabled by default for everyone. It can be disabled by setting
`timeout` to `infinity` although that is definitely not encouraged.

Inspired by the contribution from @naryl on github.
2013-01-06 19:49:01 +01:00
Loïc Hoguin
faeb37ed80 Add cowboy_req:set_resp_body_fun/2
This allows streaming a body without knowing the length in advance.
Also allows {stream, StreamFun} response body in the REST code.
2013-01-05 23:35:30 +01:00
Loïc Hoguin
6edea1c123 Fix a small warning in eunit_SUITE 2013-01-05 23:35:13 +01:00
Loïc Hoguin
58e89e2189 Change the response body streaming fun interface
Before we were required to get the socket and transport ourselves,
now they're passed to the function.
2013-01-05 20:19:43 +01:00
Loïc Hoguin
d8be610d4c Stop using rebar in the Makefile
First and foremost: yes, you can still use Cowboy as a rebar dependency.
This commit only removes the use of rebar when *developing* Cowboy, not
when *using* Cowboy.

Over the past two years I went from very happy with rebar to unsatisfied
and most recently found it counter productive in many ways, from having
insane default configuration to various unefficient operations. The earlier
reversal from 'rebar ct' to 'ct_run' made my workflow much more natural,
as I always needed to look at 'logs/raw.log' to find out what was wrong,
anyway. Why not let 'ct_run' output it directly instead? Removing rebar
made my life easier.

If you wonder why I don't patch rebar, there's two reasons. First is that
the direction taken by rebar isn't compatible with my views, and this
would be a huge fight to steer it in another direction. I got other,
more important fights to make. Second is that I'd rather patch OTP so
that everyone benefits from it, not just users of rebar.

Anyway this isn't my personal blog so I will stop babbling here. There's
a few important things to note relative to this commit:

 *  You don't need rebar to work on Cowboy anymore
 *  The eunit tests are now ran through common_test

Ping me if it doesn't work out for you.
2013-01-05 17:25:04 +01:00
Loïc Hoguin
7d2a481401 Use ct_run instead of rebar ct for running ct tests
Small tweak to the autobahn test file, we look for the python2
executable now. It'll make my life easier.
2013-01-04 17:56:49 +01:00
Loïc Hoguin
54063de2ff Hello 2013 2013-01-04 15:10:03 +01:00
Loïc Hoguin
1b3f510b7e Add middleware support
Middlewares allow customizing the request processing.

All existing Cowboy project are incompatible with this commit.
You need to change `{dispatch, Dispatch}` in the protocol options
to `{env, [{dispatch, Dispatch}]}` to fix your code.
2013-01-03 22:47:51 +01:00
Loïc Hoguin
31c7bf7234 Merge branch 'fix-websocket-timeout' of git://github.com/jeremyong/cowboy 2012-12-22 18:32:35 +01:00
Jeremy Ong
5f122d9fa6 Cancel timer only on websocket_data receives or sends
This commit prevents erlang messages from keeping a websocket connection
alive. Previously, the timer was canceled upon any activity. Now, the
timeout is only canceled when actual data is sent from the client. The
handler_loop_timeout/1 function is called from websocket_data/4 instead
of handler_before_loop/4. It is also called after every successful reply
in handler_call/4.
2012-12-22 18:32:15 +01:00
Loïc Hoguin
7ff2a62585 Make sure an incorrect port returns a 400 error 2012-12-22 16:45:04 +01:00
Loïc Hoguin
6d4e15705f Add {close, StatusCode, Payload} and fix {close, Payload} 2012-12-08 19:11:56 +01:00