0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 04:30:25 +00:00
Commit graph

1091 commits

Author SHA1 Message Date
Loïc Hoguin
41ac668ac7 Add a test with host ending in a dot in the router 2015-02-01 19:34:10 +01:00
Loïc Hoguin
02b1b28178 Discard whitespace at the end of header values early
This is more in line with what RC7230 says, and will allow simplifying
the parsing code of a few headers in cowlib.
2014-12-21 16:23:46 +02:00
Takeru Ohta
c0672b8433 Add typespecs for state record in cowboy_spdy module 2014-12-05 05:05:23 +09:00
Loïc Hoguin
999dc5b7c1 Rename 'halt' to 'stop' for better consistency
Now everywhere in Cowboy when we want to stop something we return
a 'stop' tuple instead of one of the many choices depending on
context that we had before.

This particular change affects middlewares, sub protocols and
REST handlers which were using 'halt' to stop processing.
2014-11-07 20:19:05 +02:00
Loïc Hoguin
8cbd8c1882 Rename 'shutdown' close reason and tuples to 'stop'
The 'shutdown' atom has a specific meaning inside OTP. We are
instead going to use 'stop' which is pretty much the equivalent
of what we actually do. 'shutdown' is now reserved for future
special processes implementation.
2014-11-07 19:22:36 +02:00
Loïc Hoguin
903f6f4c7d Update erlang.mk 2014-11-07 14:25:34 +02:00
Loïc Hoguin
5ff3fdd91e Update version to 2.0.0-pre.1 2014-10-04 17:01:43 +03:00
Loïc Hoguin
21d9ebe33b Reverse the order of arguments of match_* functions
Wasn't following the same order as the rest of the module.
2014-10-04 13:21:16 +03:00
Loïc Hoguin
4bc8e330fa Remove the REST known_content_type callback
This callback was simply useless.
2014-10-03 18:52:14 +03:00
Loïc Hoguin
bee5ca852b Replace some /binary to /bits in binary pattern matching
We don't need the extra check for multiple of 8 bits.
2014-10-03 18:25:29 +03:00
Loïc Hoguin
8e17d492b3 Fix a compile issue caused by a warning 2014-10-03 18:11:29 +03:00
Loïc Hoguin
403895a641 Fix two edge cases when the request-line provided is invalid 2014-10-03 17:19:04 +03:00
Andrew Houghton
d1898b969e Req#http_req.peer can be 'undefined'; update spec accordingly 2014-10-01 09:55:51 -04:00
Loïc Hoguin
0dc063ab7d Improve handler interface and documentation
This change simplifies a little more the sub protocols mechanism.
Aliases have been removed. The renaming of loop handlers as long
polling handlers has been reverted.

Plain HTTP handlers now simply do their work in the init/2
callback. There is no specific code for them.

Loop handlers now follow the same return value as Websocket,
they use ok to continue and shutdown to stop.

Terminate reasons for all handler types have been documented.
The terminate callback is now appropriately called in all cases
(or should be).

Behaviors for all handler types have been moved in the module
that implement them. This means that cowboy_handler replaces
the cowboy_http_handler behavior, and similarly cowboy_loop
replaces cowboy_loop_handler, cowboy_websocket replaces
cowboy_websocket_handler. Finally cowboy_rest now has the
start of a behavior in it and will have the full list of
optional callbacks defined once Erlang 18.0 gets released.

The guide has been reorganized and should be easier to follow.
2014-09-30 20:12:13 +03:00
Loïc Hoguin
5ce4c2bfb4 Unify the init and terminate callbacks
This set of changes is the first step to simplify the
writing of handlers, by removing some extraneous
callbacks and making others optional.

init/3 is now init/2, its first argument being removed.

rest_init/2 and rest_terminate/2 have been removed.

websocket_init/3 and websocket_terminate/3 have been removed.

terminate/3 is now optional. It is called regardless of
the type of handler, including rest and websocket.

The return value of init/2 changed. It now returns
{Mod, Req, Opts} with Mod being either one of the four
handler type or a custom module. It can also return extra
timeout and hibernate options.

The signature for sub protocols has changed, they now
receive these extra timeout and hibernate options.

Loop handlers are now implemented in cowboy_long_polling,
and will be renamed throughout the project in a future commit.
2014-09-26 15:58:44 +03:00
Loïc Hoguin
fd37fad592 Small tweak from erlang:error/1 to error/1 2014-09-24 15:07:59 +03:00
Loïc Hoguin
c56bada509 Remove the error tuple return value for middlewares
It wasn't interesting compared to simply returning a halt tuple
with an explicit reply.
2014-09-24 15:03:10 +03:00
Loïc Hoguin
aa4d86b81f Remove the onrequest hook
It was redundant with middlewares. Allows us to save a few operations
for every incoming requests.
2014-09-24 14:39:17 +03:00
Loïc Hoguin
25259671f5 Make routing constraints use the fields format
This makes routing more in line with the rest of Cowboy and
allows us to use cowboy_constraints directly.
2014-09-23 21:36:52 +03:00
Loïc Hoguin
f1c3b6d76f Breaking update of the cowboy_req interface
Simplify the interface for most cowboy_req functions. They all return
a single value except the four body reading functions. The reply functions
now only return a Req value.

Access functions do not return a Req anymore.

Functions that used to cache results do not have a cache anymore.

The interface for accessing query string and cookies has therefore
been changed.

There are now three query string functions: qs/1 provides access
to the raw query string value; parse_qs/1 returns the query string
as a list of key/values; match_qs/2 returns a map containing the
values requested in the second argument, after applying constraints
and default value.

Similarly, there are two cookie functions: parse_cookies/1 and
match_cookies/2. More match functions will be added in future commits.

None of the functions return an error tuple anymore. It either works
or crashes. Cowboy will attempt to provide an appropriate status code
in the response of crashed handlers.

As a result, the content decode function has its return value changed
to a simple binary, and the body reading functions only return on success.
2014-09-23 16:43:29 +03:00
Michael Truog
a32a476bf2 Add cowboy_req:part/2 export 2014-08-12 08:31:30 -07:00
Loïc Hoguin
260fc1e60b Handle absolute URIs that lack a path entirely 2014-08-06 11:32:58 +02:00
Loïc Hoguin
3625d6a2e2 Accept absolute URI scheme as uppercase
We should be doing a case insensitive comparison to be correct,
but this is more expensive. Almost all clients send lowercase,
this patch fixes handling of the aws/aws-sdk-php client which
sends uppercase, and no known client sends mixed case so I am
holding back on the more expensive solution for the moment.
2014-08-06 11:15:26 +02:00
Loïc Hoguin
021f4f6069 Update Cowboy to 1.0.0 2014-08-01 14:49:02 +02:00
Fred Hebert
b10b34a8f2 Support ad-hoc keep-alive for HTTP/1.0 Clients
Only go for keep-alive if they submit a 'connection: keep-alive' header
in the request, keep behaviour the same otherwise.

The new RFC 7230 (http://tools.ietf.org/html/rfc7230#section-6.3)
states:

    If the received protocol is HTTP/1.0, the "keep-alive" connection
    option is present, the recipient is not a proxy, and the recipient
    wishes to honor the HTTP/1.0 "keep-alive" mechanism, the
    connection will persist after the current response;

Even though clients are discouraged from doing so in Appendix A.1.2
(http://tools.ietf.org/html/rfc7230#appendix-A.1.2)
2014-07-14 10:11:03 -04:00
Loïc Hoguin
9980348a1c Remove deprecated body reading interface 2014-07-12 15:42:45 +02:00
Loïc Hoguin
ecbebeefe8 Remove useless todo comments 2014-07-12 14:50:01 +02:00
Loïc Hoguin
e2b5c21443 Drop R15 support 2014-07-12 14:19:29 +02:00
Loïc Hoguin
97a3108576 Reply with 400 on header parsing crash
This is a first step to improve the HTTP status codes returned
by Cowboy on crashes. We will tweak it over time.

Also fixes a small bug where two replies may have been sent
when using loop handlers under rare conditions.
2014-07-12 12:09:43 +02:00
Loïc Hoguin
fd423eb170 Merge branch 'fix-spdy-parse-frame' of git://github.com/voluntas/cowboy
A fix for a possible bug has been made to the original patch.
2014-07-07 17:22:36 +02:00
Loïc Hoguin
4eee573700 Return 422 instead of 400 when AcceptResource returns false
422 is undefined for HTTP and interpreted as 400.
2014-06-30 17:49:36 +02:00
Loïc Hoguin
8cc353114e Update specs that were too wide 2014-06-30 17:36:43 +02:00
Nakai Ryosuke
fec3355192 Fix cowboy_spdy parse frame 2014-06-28 20:13:41 +09:00
Loïc Hoguin
ee3ad5e510 Update Cowboy to 0.10.0 2014-06-10 12:07:11 +02:00
Loïc Hoguin
7cd3ecc6b6 Fix specs and a weird value in cowboy_spdy 2014-06-10 09:24:06 +02:00
Loïc Hoguin
fc7e038fba Merge branch 'binary-expires' of git://github.com/NineFX/cowboy 2014-06-10 08:39:40 +02:00
Drew Varner
6ed25fd60b Allow users to pass a raw binary() as the expires header. 2014-06-10 00:12:26 +02:00
Loïc Hoguin
5d1d9af6cd Add a return value to onresponse hook to override status/headers
This would allow us to override them without messing up the body,
and would make it usable with the static file handler for example.

Experimental at this point.
2014-06-03 18:31:05 +02:00
Loïc Hoguin
0c37925642 Add request body reading options
The options were added to allow developers to fix timeout
issues when reading large bodies. It is also a cleaner and
easier to extend interface.

This commit deprecates the functions init_stream, stream_body
and skip_body which are no longer needed. They will be removed
in 1.0.

The body function can now take an additional argument that is a
list of options. The body_qs, part and part_body functions can
too and simply pass this argument down to the body call.

There are options for disabling the automatic continue reply,
setting a maximum length to be returned (soft limit), setting
the read length and read timeout, and setting the transfer and
content decode functions.

The return value of the body and body_qs have changed slightly.
The body function now works similarly to the part_body function,
in that it returns either an ok or a more tuple depending on
whether there is additional data to be read. The body_qs function
can return a badlength tuple if the body is too big. The default
size has been increased from 16KB to 64KB.

The default read length and timeout have been tweaked and vary
depending on the function called.

The body function will now adequately process chunked bodies,
which means that the body_qs function will too. But this means
that the behavior has changed slightly and your code should be
tested properly when updating your code.

The body and body_qs still accept a length as first argument
for compatibility purpose with older code. Note that this form
is deprecated and will be removed in 1.0. The part and part_body
function, being new and never having been in a release yet, have
this form completely removed in this commit.

Again, while most code should work as-is, you should make sure
that it actually does before pushing this to production.
2014-06-02 23:09:43 +02:00
Loïc Hoguin
da29d8138d Merge branch 'language-range-header' of git://github.com/NineFX/cowboy 2014-04-26 14:38:24 +02:00
Loïc Hoguin
980342f73c Make loop handlers work with SPDY
Adds a loop_handler test suite that runs all tests under HTTP, HTTPS,
SPDY each with and without the compress option enabled.

Fixes output filtering that used to filter more than it should have.
This forces us to parse the string sent by the emulator, which means
it's probably not perfect yet. But it should at least not hide errors
we want to see.

Fix a crash in the output filtering code that entirely disabled
output. Now when there is a crash the normal tty output is restored.

Handlers are now in test/handlers/ as they can be reused between
suites.

Only generate a single certificate for the whole ct run to speed
things up when we got many different test groups each needing
certificates.
2014-04-26 13:46:55 +02:00
Loïc Hoguin
5c2adc167a Merge branch 'fix/basic-auth-empty-password' of git://github.com/soundrop/cowboy 2014-04-17 13:23:48 +02:00
Loïc Hoguin
0502452967 Update cowlib to 0.6.1 2014-03-27 11:39:09 +01:00
Loïc Hoguin
c9b9644aa3 Add +warn_missing_spec and fix specs 2014-03-27 11:30:44 +01:00
Loïc Hoguin
17af50812c Remove outdated comments, all edoc, plus a few minor tweaks 2014-03-26 19:05:59 +01:00
Loïc Hoguin
abf246c9aa Make the latin1 cyrillic route tests work on R17+
Instead of relying on the encoding of the file we now simply
have list of numbers as they would be inside a latin1 file.
2014-03-25 11:42:57 +01:00
Loïc Hoguin
0c0caa3a47 Don't flush the resp_sent message if connection is closed
Tiny optimization.
2014-03-25 11:06:21 +01:00
Loïc Hoguin
704f61c9d1 Remove cowboy_client; use gun for the HTTP test suite 2014-03-24 14:25:09 +01:00
Loïc Hoguin
d4ce3c638d Use the new chunked and identity transfer decoding code from cowlib 2014-03-24 14:24:52 +01:00
Loïc Hoguin
dbf7b1c5e5 Use cow_http_hd:parse_transfer_encoding/1 where applicable 2014-03-24 14:24:52 +01:00