aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_protocol.erl
AgeCommit message (Collapse)Author
2014-06-02Add request body reading optionsLoïc Hoguin
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-03-26Remove outdated comments, all edoc, plus a few minor tweaksLoïc Hoguin
2014-03-25Don't flush the resp_sent message if connection is closedLoïc Hoguin
Tiny optimization.
2014-02-27Keep the whitespace from multiline headersLoïc Hoguin
Before, we could have Header: the value is multiline Become "the valueis multiline". Now it will properly be "the value is multiline".
2014-02-06Update copyright yearsLoïc Hoguin
2014-02-06Use the INLINE_LOWERCASE macro in the request parsing codeLoïc Hoguin
Since I made it for similar code in cowlib, let's use it here too.
2013-11-09Use try/catch instead of catchLoïc Hoguin
Thanks Richard Carlsson for the remainder.
2013-09-04Make cowlib a proper dependencyLoïc Hoguin
Start moving a few functions from Cowboy into cowlib.
2013-09-03add unit test for cowboy_protocol:parse_host/1YAMAMOTO Takashi
2013-09-03cowboy_protocol: accept host using ipv6 literalYAMAMOTO Takashi
2013-08-24Simpler code for sending errors following crashesLoïc Hoguin
2013-05-30Add experimental and incomplete SPDY supportLoïc Hoguin
The SPDY connection processes are also supervisors. Missing: * sendfile support * request body reading support
2013-05-16Use the type ranch:ref() instead of any() where applicableLoïc Hoguin
2013-05-16Add cowboy_protocol:opts() typeLoïc Hoguin
Should improve the detection of wrong protocol options.
2013-05-16Move cowboy_protocol:onresponse_fun() to cowboy:onresponse_fun()Loïc Hoguin
2013-05-16Move cowboy_protocol:onrequest_fun() to cowboy:onrequest_fun()Loïc Hoguin
2013-05-16Move cowboy_http:status() to cowboy:http_status()Loïc Hoguin
2013-05-16Move cowboy_http:headers() to cowboy:http_headers()Loïc Hoguin
2013-05-16Make the HTTP version type more practicalLoïc Hoguin
Now instead of {1, 1} we have 'HTTP/1.1', and instead of {1, 0} we have 'HTTP/1.0'. This is more efficient, easier to read in crash logs, and clearer in the code.
2013-05-15Remove cowboy_req:fragment/1Loïc Hoguin
Clients do not send it. We skip the value if we receive it now, as it shouldn't happen, and won't for all the mainstream clients.
2013-04-03Update Ranch to 0.8.0Loïc Hoguin
2013-03-06Stop using binary:match in cowboy_protocolLoïc Hoguin
It's been found slower than a custom equivalent to what we were using it for. As this is the critical path we prefer the custom solution.
2013-02-12Make cowboy_protocol:resume/6 privateLoïc Hoguin
2013-02-06Fix crashes when creating the requestLoïc Hoguin
We now obtain the peer address before creating the Req object. If an error occurs, then something went wrong, we close the connection nicely directly.
2013-01-29Do not attempt to skip the request body on Connection: closeLoïc Hoguin
2013-01-18Set max_keepalive default to 100 instead of infinityLoïc Hoguin
2013-01-07Add optional automatic response body compressionLoïc Hoguin
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-06Add protection against slowloris vulnerabilityLoïc Hoguin
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-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-22use the original request when available for error_terminateTom Burdick
this change makes sure that once a request has been created the error_terminate/3 function uses the original request instead of making a new empty one with undefined values making the request attributes easier to look at in many error cases Conflicts: src/cowboy_protocol.erl
2012-12-22Make sure an incorrect port returns a 400 errorLoïc Hoguin
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-03Allow passing the Req and an updated Opts when upgrading protocolsLoïc Hoguin
2012-11-28Clarify error reports indicating they come from CowboyLoïc Hoguin
2012-11-27Fixed onrequest path-related issueserge
2012-10-27Return "400 Bad Request" instead of crashing process on incorrect queries ↵Ivan Blinkov
like /%qq
2012-10-04The onresponse hook now receives 4 arguments, including the bodyLoïc Hoguin
We do not always provide the body however. It is not available when using chunked replies, or when using set_resp_body_fun.
2012-09-29Add max_headers optionLoïc Hoguin
It is only enforced when Cowboy needs to wait for more data. Also fix a few types and a few status codes.
2012-09-29Add missing options in the cowboy_protocol documentationLoïc Hoguin
2012-09-29Remove the urldecode cowboy_protocol optionLoïc Hoguin
This allows inconsistent behavior and is not used enough to be supported.
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-26Optimize cowboy_protocolLoïc Hoguin
* #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-23Extract the buffer out of the #state{} in cowboy_protocolLoïc Hoguin
This reduces the number of operations done each time the buffer changes.
2012-09-23Improve state reset between requestsLoïc Hoguin
2012-09-23Use binary:match/2 instead of binary:split/2Loïc Hoguin
The former is a BIF while the latter is not.
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.
2012-09-17Add types for onrequest and onresponse funsLoïc Hoguin
2012-09-17Replace many proplists:get_value/{2,3} calls by BIFsLoïc Hoguin
Originally suggested by Roberto Ostinelli.
2012-09-17Include the eunit file only if TEST is definedLoïc Hoguin