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
Loïc Hoguin
8bc6bde62f Remove the dependency on httpd_util
Add the function cowboy_clock:rfc1123/1 that formats the given
date to the RFC1123 format.
2012-12-03 15:57:27 +01:00
Loïc Hoguin
5ef4a15b48 Allow passing the Req and an updated Opts when upgrading protocols 2012-12-03 15:52:09 +01:00
Loïc Hoguin
067958abd2 Add more frame types available in websocket replies
We can now reply empty close, ping and pong frames, or close
frames with a payload.

This means that we can send a frame and then close the connection
in a single operation.

If a close packet is sent, the connection is closed immediately,
even if there was frames that remained to be sent. Cowboy will
silently drop any extra frames in the list given as a reply.
2012-12-02 21:37:24 +01:00
Loïc Hoguin
5c315ab142 Return a 400 error if the Accept header was incorrect 2012-11-30 16:44:57 +01:00
Loïc Hoguin
5f6b6b6f6d Add a better error message when user callbacks are not exported 2012-11-29 16:15:28 +01:00
Loïc Hoguin
916bfde1f8 Fix a test that worked intermittently 2012-11-27 17:31:54 +01:00
Loïc Hoguin
09914c4693 Allow websocket handlers to reply more than one frame
Instead of returning {text, Data}, you can now return
[{text, Data}, {text, Data2}, ...].
2012-10-11 21:46:43 +02:00
Loïc Hoguin
e128e935af Fix the autobahn test suite
All tests still pass! (Excluding UTF-8 of course.)
2012-10-11 20:35:23 +02:00
Loïc Hoguin
aeb86e70c1 Add crypto into the required applications
As suggested by @prof3ta.
2012-10-11 20:13:23 +02:00
Loïc Hoguin
76cd1e40c9 The onresponse hook now receives 4 arguments, including the body
We do not always provide the body however. It is not available
when using chunked replies, or when using set_resp_body_fun.
2012-10-04 22:59:33 +02:00
Loïc Hoguin
2e0a2a1c9e Add max_headers option
It is only enforced when Cowboy needs to wait for more data.

Also fix a few types and a few status codes.
2012-09-29 13:57:30 +02:00
Loïc Hoguin
b2243aa544 Optimize cowboy_protocol
* #state{} changes are avoided where possible
* #state{} is now smaller and use less memory
* the Req object is created only after the whole request is parsed
* parsing makes use of a single binary match context
* external calls are avoided in the critical path
* URL fragment is now extracted properly (retrieval API next commit)
* argument orders to local functions modified to avoid extra operations
* dispatching waits as long as possible before tokenizing host/path
* handler opts are no longer shown in the error messages except in init

The code may not look as beautiful as it was before. But it really
is, for parsing code. The parsing section of the file may be skipped
if your eyes start to burn.
2012-09-26 14:20:29 +02:00
Loïc Hoguin
3c10d54883 Removal of binary:split from cowboy_dispatcher and small optimizations
The internal host_tokens value now has host tokens in reverse order
compared to before. This allows us to remove one lists:reverse call.
2012-09-24 04:53:12 +02:00
Loïc Hoguin
e27fd5fcb9 Make multipart part headers binary lowercase
Here we do not remove decode_packet yet, we just lowercase the
header name and transform it into a binary if needed, to fix
the consistency issue.
2012-09-21 13:07:51 +02:00
Loïc Hoguin
34021666cb Don't use decode_packet/3 for parsing the headers
Header names are now binaries. Since header names are case insensitive
they are all converted to lowercase. For example: <<"content-length">>.

The max_line_length option was removed. Three new options have been
added instead:

 *  max_request_line_length (defaults to 4096)
 *  max_header_name_length (defaults to 64)
 *  max_header_value_length (defaults to 4096)
2012-09-21 09:18:56 +02:00
Loïc Hoguin
8497c8bbcd Don't use decode_packet/3 for parsing the request-line
First step in making all methods and header names binaries to
get rid of many inconsistencies caused by decode_packet/3.

Methods are all binary now. Note that since they are case
sensitive, the usual methods become <<"GET">>, <<"POST">> and so on.
2012-09-21 08:54:57 +02:00
Loïc Hoguin
8d5f8db90a Improve consistency of return types for cowboy_req API
The signature of parse_header, body_qs, multipart_data and
the set_resp_* functions has changed.

See the cowboy_req module edoc for more details.
2012-09-17 13:56:58 +02:00
Loïc Hoguin
79839b7bb5 Replace cowboy_req:path/1 with cowboy_req:raw_path/1
The latter is much more useful than the former, which ends up
being removed.
2012-09-10 12:26:04 +02:00
Loïc Hoguin
0e3adf1fee Rename cowboy_http_websocket to cowboy_websocket 2012-08-27 14:00:28 +02:00
Loïc Hoguin
f39c001c03 Rename cowboy_http_static to cowboy_static 2012-08-27 13:53:27 +02:00
Loïc Hoguin
6d84afd16d Rename cowboy_http_rest to cowboy_rest 2012-08-27 13:39:59 +02:00
Loïc Hoguin
d3dcaf109b Rename cowboy_http_req to cowboy_req 2012-08-27 13:28:57 +02:00
Loïc Hoguin
9e2622becb Rename cowboy_http_protocol to cowboy_protocol 2012-08-27 12:58:04 +02:00
Loïc Hoguin
cc2e084d45 Update behaviours for R15B+
This effectively drops the R14B compatibility.

The cowboy_req:req() type will be introduced in a future commit.
It refers to the #http_req{} record.
2012-08-27 12:50:00 +02:00
Loïc Hoguin
e4124de2c7 Switch to Ranch for connection handling
This is the first of many API incompatible changes.

You have been warned.
2012-08-27 11:50:35 +02:00
Loïc Hoguin
0c2e2224e3 Update version to 0.6.0
Also update the CHANGELOG and copyright years.
2012-05-23 14:53:48 +02:00
Loïc Hoguin
1a1b01c7c4 Remove a dumb warning when running the tests 2012-05-21 16:46:18 +02:00
Loïc Hoguin
295dc64eaa Merge branch 'serve-static-file' of https://github.com/klaar/cowboy
Fix alphabetical order since @klaar seems to have issues with it. ;)
2012-05-21 16:33:37 +02:00
Loïc Hoguin
cc6c4e39de Fix a bug preventing 'onresponse' from being called on errors 2012-05-21 15:17:24 +02:00
Loïc Hoguin
8363e8995a Small updates to the ROADMAP and doc comments 2012-05-21 08:49:22 +02:00
Loïc Hoguin
90bae59307 Add a test checking requests with size around the MTU 2012-05-05 07:53:17 +02:00
Loïc Hoguin
0406a632dc Merge branch 'response-hook' 2012-05-04 06:32:12 +02:00
Loïc Hoguin
57fda14217 Add an 'onresponse' hook
This new protocol option is a fun.

It expects 3 args: the Status code used in the reply (this is the
cowboy_http:status() type, it can be an integer or a binary), the
headers that will be sent in the reply, and the Req. It should
only return a possibly modified Req. This can be used for many
things like error logging or custom error pages.

If a reply is sent inside the hook, then Cowboy will discard the
reply initially sent. Extra caution must be used in the handlers
making use of inline chunked replies as they will throw an error.

This fun cannot be used as a filter, you can either observe the
reply sent or discard it to send a different one instead.

The hook will not be called for replies sent from inside the hook.
2012-05-04 06:24:10 +02:00
Loïc Hoguin
dab6648290 Add a test for HTTP handlers loop timeouts 2012-05-02 20:27:44 +02:00
Magnus Klaar
8168ae96c8 Add file option to cowboy_http_static 2012-04-30 23:50:23 +02:00
Loïc Hoguin
ee8c50c5ab Fix and rework the HTTP test suite
Use a proper HTTP client to run all tests. This client is currently
undocumented and should not be used.

Includes a few fixes:

* Fix a bug in the max_keepalive test
* Fix a bug with max_keepalive handling
* Fix a bug in stream_body/1 where data was lost under some conditions

The tests now run quite faster than before.

All the tests now run twice: once for TCP, once for SSL.
2012-04-29 15:22:20 +02:00
Loïc Hoguin
e8ee64777c Merge branch 'websocket-fragments' of https://github.com/klaar/cowboy 2012-04-06 22:18:09 +02:00
Magnus Klaar
80c67bff33 Update autobahn suite to use autobahntestsuite 2012-04-06 17:53:53 +02:00
Magnus Klaar
0b15ed914d Add support for fragmented websocket messages 2012-04-05 22:02:04 +02:00
Loïc Hoguin
95e05d822f Add chunked transfer encoding support and rework the body reading API
Introduces 3 low level functions and updates the existing higher
levels functions. The new primitives are has_body/1, body_length/1
and stream_body/1. In addition to that, a helper function
init_stream/4 has been added.

Streaming a body implies to decode the Transfer-Encoding and
Content-Encoding used for the body. By default, Cowboy will try
to figure out what was used and decode them properly. You can
override this if you want to disable this behavior or simply
support more encodings by calling the init_stream/4 function
before you start streaming the body.
2012-04-01 21:25:55 +02:00
Loïc Hoguin
8e2cc3d7f1 Add an 'onrequest' hook for HTTP
This new protocol option is a fun.

It expects a single arg, the Req, and should only return a possibly
modified Req. This can be used for many things like URL rewriting,
access logging or listener-wide authentication.

If a reply is sent inside the hook, then Cowboy will consider the
request handled and will move on to the next one.
2012-03-15 22:29:38 +01:00
Loïc Hoguin
36a6823e50 Do not send chunked Transfer-Encoding replies for HTTP/1.0
Fixes compatibility issue #140 reported by @majek.
2012-03-13 03:00:05 +01:00
Magnus Klaar
9922de6d9e Tests and fixes for the generate_etag/2 callback
The return value from the generate_etag/2 callback is expected to be a
binary tagged with either weak or strong. This binary is quoted, and
may be prefixed with W/ before it is set as the value of the ETag header
in the response.

For backwards compatibility with older handlers where the return value
was expected to be a quoted binary a function has been added to parse any
return values that are untagged binaries. All untagged binaries are expected
to be a valid value for the ETag header.
2012-02-29 22:32:37 +01:00
David Kelly
e7b6e2a402 Added absoluteURI support
If requests go through a proxy, they will have the original uri in the
request, i.e. : GET http://proxy.server.uri/some/query/string  HTTP 1.1 ...

That was problematic -- cowboy_http_protocol:request didn't know what to
to with the result of decode_packet applied to this, which would be something
like:

``` erlang
{http_request,'GET',{absoluteURI,http,<<"proxy.server.uri">>,
	undefined,<<"/some/query/string">>},{1,1}}
```

So, I just ignore the host, grab the path and pass into

``` erlang
cowboy_http_protocol:request({http_request, Method, {abs_path, Path},
	Version}, State)
```

Seems to do the trick without much effort.
2012-02-02 20:25:23 +01:00
Loïc Hoguin
9823450cc3 Merge branch 'autobahn-suite' of https://github.com/klaar/cowboy
This needs python2 to be the default python in /usr/bin/python.
2012-01-31 12:17:29 +01:00
Loïc Hoguin
bb08cf85e3 Remove a leftover ct:print 2012-01-26 23:27:34 +01:00
Tom Burdick
ca42ea1620 Handle delete better when no delete_resource function is implemented 2012-01-26 18:21:20 +01:00
Magnus Klaar
8808825173 Add Autobahn test suite for websockets
We're using the existing test suite for websocket servers from the
Autobahn project to verify that out websockets implementation is
sane. A CT test suite and python module wrapping the test suite has
been added. The test suite is run when the 'make inttests' target
is executed.
2012-01-25 12:10:05 +01:00
Loïc Hoguin
dd08a90568 Merge branch 'master' of https://github.com/bfrog/cowboy 2012-01-23 21:57:20 +01:00
Tom Burdick
62de899c95 added test for posting to a rest controller where forbidden returns true on a keep alive socket 2012-01-23 12:42:04 -06:00