aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_rest.erl
AgeCommit message (Collapse)Author
2013-08-24Crash on failure, don't report errorsLoïc Hoguin
When something went wrong in a handler we used to report errors and then terminate the process normally. This doesn't work so well with links which won't detect failure. Now we still catch the error, but throw another one with more details on why it happened, including the Req object information and the stacktrace. Ranch will then print an error message with all this information. Because we crash directly, this also means that we will not hog resources unnecessarily for too long when something bad happens.
2013-06-08Merge branch 'dont_overwrite_stacktrace' of git://github.com/urbanserj/cowboyLoïc Hoguin
2013-06-07Don't overwrite stacktrace in `cowboy_rest:error_terminate/2`Sergey Urbanovich
This stacktrace is very useful in the `onresponse` hook. For example: ```erlang internal_error_hook(500, Headers, <<>>, Req) -> StackTrace = erlang:get_stacktrace(), Headers0 = [{N, V} || {N, V} <- Headers, N =/= <<"content-length">>], Body = io_lib:format("~p", [StackTrace]), {ok, Req0} = cowboy_req:reply(500, Headers0, Body, Req), Req0; internal_error_hook(Status, Headers, Body, Req) -> {ok, Req0} = cowboy_req:reply(Status, Headers, Body, Req), Req0. ```
2013-05-31Merge branch 'rest_method' of git://github.com/dvv/cowboyLoïc Hoguin
2013-05-16The charset iso-8859-1 is added only if not explicitely mentionedLoïc Hoguin
It was added all the time when * was missing, the RFC specifies it should only be added if it wasn't already present, though.
2013-05-16charsets_provided/2 returns a list of charsetsLoïc Hoguin
It incorrectly returned a tuple containing the charset and an associated quality which wasn't being used.
2013-05-16Make the return value of AcceptResource callback consistentLoïc Hoguin
2013-04-30Empty methods list allowedVladimir Dronnikov
2013-04-29Fix a bug in REST when allowed_methods is defined when method is OPTIONSLoïc Hoguin
2013-04-26Add chunked response body funJames Fish
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-26Fix indenting issues in `cowboy_rest.erl`Seletskiy Stanislav
2013-04-26Add default CTP: "text/html" maps to `to_html`Seletskiy Stanislav
2013-04-20REST is no longer experimentalLoïc Hoguin
2013-04-20Fix POST behavior in RESTLoïc Hoguin
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-15Build Allow header with a binary comprehensionLoïc Hoguin
2013-04-12Add default operations for OPTIONS method in RESTLoïc Hoguin
It defaults to setting the Allow header to "HEAD, GET, OPTIONS".
2013-04-12rest: reject incorrect content-type headerVladimir Dronnikov
2013-04-11Don't accept TRACE or CONNECT methods by default in RESTLoïc Hoguin
For the simple reason that the REST code does nothing about them.
2013-04-11Remove process_post, post_is_create, create_path, created_path callbacksLoïc Hoguin
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-03-03Add '*' matcher for parametersSlava Yurin
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-02-16Add sub protocol behaviourJames Fish
2013-02-09Make sure rest_terminate is always calledLoïc Hoguin
Also improves error reporting.
2013-02-09Fix Location headerSlava Yurin
Fix #414
2013-01-29Merge branch 'patch-1' of https://github.com/CamShaft/cowboyLoïc Hoguin
Conflicts: src/cowboy_rest.erl
2013-01-29allow POST rest handling to specify path after accepting contentTom Burdick
2013-01-29add patch support to cowboy_restTom Burdick
2013-01-22Fix handler state change in cowboy_restSlava Yurin
2013-01-18Remove a few old @todo commentsLoïc Hoguin
2013-01-05Add cowboy_req:set_resp_body_fun/2Loïc Hoguin
This allows streaming a body without knowing the length in advance. Also allows {stream, StreamFun} response body in the REST code.
2013-01-03Add middleware supportLoïc Hoguin
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.
2012-12-30Return 422 instead of 500 when handling bodyCameron Bytheway
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-13Make the arguments to error_logger more consistentAndrew Thompson
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-11Fix charset not working properly for RESTLoïc Hoguin
2012-12-03Remove the dependency on httpd_utilLoïc Hoguin
Add the function cowboy_clock:rfc1123/1 that formats the given date to the RFC1123 format.
2012-11-30Return a 400 error if the Accept header was incorrectLoïc Hoguin
2012-11-29Add a better error message when user callbacks are not exportedLoïc Hoguin
2012-11-28Clarify error reports indicating they come from CowboyLoïc Hoguin
2012-11-28Merge branch 'master' of git://github.com/chancila/cowboyLoïc Hoguin
2012-11-27charsets_provided in rest module to return [binary()]Cristian Hancila
2012-11-27Cosmetic changes to various documentation filesLoïc Hoguin
2012-11-26Fix a small typo in the rest_init error messageLoïc Hoguin
2012-11-24Merge pull request #297 from puzza007/masterLoïc Hoguin
Correct spelling in rest callback name
2012-11-16REST: Fix the status code sent if the content type isn't knownLoïc Hoguin
2012-11-10Convert headers to lowercaseJulian Squires
2012-10-25musnt is not the correct contraction of mustn't - use must_not insteadPaul Oliver
2012-10-13Clarify docs for known_methods and allowed_methods.Josh Allmann
2012-10-11Fix Vary header, was wrongly named Variances previouslyLoïc Hoguin
2012-09-29Add cowboy_req:get/2 and :set/2 private functionsLoïc Hoguin
They should not be used unless you have a very special need, which generally involves interacting with the internals of Cowboy.
2012-09-21Don't use decode_packet/3 for parsing the headersLoïc Hoguin
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-21Don't use decode_packet/3 for parsing the request-lineLoïc Hoguin
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.