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

53 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
Seletskiy Stanislav
72a9ccacdd Fix indenting issues in cowboy_rest.erl 2013-04-26 18:34:10 +07:00
Seletskiy Stanislav
f316b47d13 Add default CTP: "text/html" maps to to_html 2013-04-26 18:34:01 +07:00
Loïc Hoguin
97b8401c45 REST is no longer experimental 2013-04-20 17:46:29 +02:00
Loïc Hoguin
711c21ac4f Fix POST behavior in REST
The resource accept callback can trigger the following responses:

 *  returns true, new resource, location header set: 201
 *  returns true, otherwise: 200, 204 or 300 (depends on body)
 *  returns false: 422
 *  returns URL, new resource: 201
 *  returns URL, otherwise: 303
2013-04-20 15:52:31 +02:00
Loïc Hoguin
8d7350fa84 Build Allow header with a binary comprehension 2013-04-15 22:15:45 +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
Vladimir Dronnikov
180143f9b2 rest: reject incorrect content-type header 2013-04-12 14:58:08 +04:00
Loïc Hoguin
ae45cecfcd Don't accept TRACE or CONNECT methods by default in REST
For the simple reason that the REST code does nothing about
them.
2013-04-11 22:25:36 +02: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
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
James Fish
6d67ad809c Add sub protocol behaviour 2013-02-16 16:19:53 +00:00
Loïc Hoguin
26935cbfb0 Make sure rest_terminate is always called
Also improves error reporting.
2013-02-09 17:05:28 +01:00
Slava Yurin
7ca591a0da Fix Location header
Fix #414
2013-02-09 11:19:25 +07: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
Tom Burdick
c4d1ee5547 add patch support to cowboy_rest 2013-01-29 11:34:20 -06:00
Slava Yurin
9aa0e1a58a Fix handler state change in cowboy_rest 2013-01-22 23:14:08 +07:00
Loïc Hoguin
09c68ca755 Remove a few old @todo comments 2013-01-18 18:21:28 +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
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
Cameron Bytheway
f1b4acbb44 Return 422 instead of 500 when handling body
Using a 4xx error would be more appropriate for this since the server is parsing the content from the client and needs to let the client know the data is malformed (not the actual HTTP request but i.e. JSON semantics). The definition for 422 is described in [RFC 4918](https://tools.ietf.org/html/rfc4918#section-11.2)
2012-12-30 22:31:07 -07:00
Andrew Thompson
d916d739d4 Make the arguments to error_logger more consistent
The purpose of this patch is to make the arguments cowboy passes to
error_logger more consistent. With this patch there's only 3 variations
on the error_logger argument list; a 5 element list, an 8 element list
and a 10 element list. In all cases, the first 3 arguments are the
Module, Function and Arity of the function being called and the
second-to-last argument is always the Request. Additionally, for lists
longer than 5 elements, the last argument is always the stack-trace.

The added consistency of the argument ordering makes it much easier to
write code in lager's error_logger handler to catch these messages and
write a pretty one-liner (while writing the full message to the
crash.log).
2012-12-13 03:38:38 -05:00
Loïc Hoguin
08a4975c34 Fix charset not working properly for REST 2012-12-11 00:05:42 +01:00
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
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
45dd67741f Clarify error reports indicating they come from Cowboy 2012-11-28 18:30:53 +01:00
Loïc Hoguin
8cd9183272 Merge branch 'master' of git://github.com/chancila/cowboy 2012-11-28 17:32:01 +01:00
Cristian Hancila
4ddacaf6f6 charsets_provided in rest module to return [binary()] 2012-11-27 15:40:44 -05:00
Loïc Hoguin
f63d3f08cf Cosmetic changes to various documentation files 2012-11-27 16:24:08 +01:00
Loïc Hoguin
5e6aab756a Fix a small typo in the rest_init error message 2012-11-26 23:06:45 +01:00
Loïc Hoguin
74ba41e239 Merge pull request #297 from puzza007/master
Correct spelling in rest callback name
2012-11-24 08:21:16 -08:00
Loïc Hoguin
3e891b7120 REST: Fix the status code sent if the content type isn't known 2012-11-16 14:02:38 +01:00
Julian Squires
dd6876f95c Convert headers to lowercase 2012-11-10 17:24:25 -05:00
Paul Oliver
8706dd8834 musnt is not the correct contraction of mustn't - use must_not instead 2012-10-25 15:29:02 -04:00
Josh Allmann
65c5d576c8 Clarify docs for known_methods and allowed_methods. 2012-10-13 15:15:15 -07:00
Loïc Hoguin
642a8f73c9 Fix Vary header, was wrongly named Variances previously 2012-10-11 20:44:53 +02:00
Loïc Hoguin
c326a195e0 Add cowboy_req:get/2 and :set/2 private functions
They should not be used unless you have a very special need,
which generally involves interacting with the internals of Cowboy.
2012-09-29 11:08:59 +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
82d7e89ea2 Remove http.hrl dependency in cowboy_rest
Only cowboy_protocol remaining now.
2012-09-17 13:57:28 +02:00
Loïc Hoguin
f205d44518 Add a function to lock request responses instead of inlining
Just more cleanup in order to have req() opaque.
2012-09-17 13:57:28 +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
e13ab806ea Add cowboy_req:delete_resp_header/2
Both requested and better for making Req opaque.
2012-09-16 03:50:56 +02:00
Loïc Hoguin
527477bd4a Introduce cowboy_req:host_url/1 to remove more duplicate code 2012-09-16 01:13:44 +02:00
Loïc Hoguin
736bcd4841 Put the method in cowboy_rest's #state{} 2012-09-15 23:53:30 +02:00
Loïc Hoguin
9ef94fb64e Introduce cowboy_req:set_meta/3 to set request metadata 2012-09-15 22:51:37 +02:00
Loïc Hoguin
bb4bd9ac96 Add a cowboy_req:to_list/1 function
Removes a lot of duplicate code when printing error messages.
2012-09-15 20:33:57 +02:00
Loïc Hoguin
d9e76d59a1 Change type #http_req{} to cowboy_req:req()
This removes cowboy_static's dependency on http.hrl.
2012-09-15 01:31:51 +02:00