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

213 commits

Author SHA1 Message Date
Loïc Hoguin
233cf43ab9 Make streamed chunk size configurable
Defaults to a maximum of 1000000 bytes.

Also standardize the te_identity and te_chunked decoding functions.
Now they both try to read as much as possible (up to the limit),
making body reading much faster when not using chunked encoding.
2013-03-05 21:54:35 +01:00
Adam Cammack
b903aca33d Make cowboy_http.erl compile with +native
Worked until 27da092
2013-02-12 11:53:47 -06:00
Loïc Hoguin
1c5ce11d13 Strip whitespaces when authorization type is unknown 2013-02-06 19:16:06 +01:00
Loïc Hoguin
f710ac86f8 Merge branch 'feature_basic_auth' of https://github.com/ivlis/cowboy 2013-01-29 22:20:59 +01:00
Ivan Lisenkov
54c6d3fa3a Implement authorization header parsing
Basic HTTP authorization according to RFC 2617 is implemented.
Added an example of its usage with REST handler.
2013-01-30 00:30:05 +04:00
Loïc Hoguin
85d05fff34 Fix chunked streaming of request body and improve speed 2013-01-29 19:12:34 +01:00
Loïc Hoguin
54063de2ff Hello 2013 2013-01-04 15:10:03 +01:00
Loïc Hoguin
659ca05c54 We accept iodata() when setting cookies; fix that 2012-12-20 14:36:40 +01:00
Loïc Hoguin
8858ca240f Fix parsing of the Cookie header
This should be equivalent to what we do in Set-Cookie. Real-world
testing is needed to confirm it works as intended.
2012-12-20 14:19:39 +01:00
Loïc Hoguin
f077c711a8 Fix cowboy_http:cookie_to_iodata/3
No more trying to quote, this is still completely broken everywhere.
2012-12-17 12:32:17 +01:00
Loïc Hoguin
6074ce4a39 Add missing quotes to quoting for cookie values 2012-12-13 16:57:58 +01:00
Loïc Hoguin
27da09282d Make cookies use universal time instead of local time
Includes:
  * cowboy_clock:rfc2109/1 now expects UTC datetime
  * Rewrite of the cookie code to cowboy_http
  * Removal of cowboy_cookies
  * Add type cowboy_req:cookie_opts/0

Cookies should now be set using cowboy_req:set_resp_cookie/3.
Code calling cowboy_cookies directly will need to be updated.
2012-12-07 15:13:35 +01:00
Loïc Hoguin
ce9aff19f0 Remove the urldecode cowboy_protocol option
This allows inconsistent behavior and is not used enough to be supported.
2012-09-29 13:03:45 +02:00
Loïc Hoguin
cd7f37d346 Optimize Connection header parsing
Still optimizing the critical path.

Removes cowboy_http:connection_to_atom/1.
2012-09-27 01:31:19 +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
332c274d87 Use binary:match/2 instead of binary:split/2 in cowboy_http
Also fix a bug introduced in a previous commit.
2012-09-23 21:25:54 +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
9090cd9765 Replace many proplists:get_value/{2,3} calls by BIFs
Originally suggested by Roberto Ostinelli.
2012-09-17 13:57:29 +02:00
Loïc Hoguin
13b743ba26 Include the eunit file only if TEST is defined 2012-09-17 13:57:29 +02:00
Loïc Hoguin
a5e75219f0 Have only one -export and -export_type per line
This should make easier spotting additions and removals in commits.
2012-08-27 12:16:07 +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
040c6dc31a Merge branch 'fix/relax-conneg-parsing' of https://github.com/tillitech/cowboy 2012-05-21 15:24:40 +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
Ali Sabil
4b43d06384 Make charsets parsing more relaxed
Certain user agents send invalid Accept-Charset headers, like the
following: "ISO-8859-1;utf-8;q=0.7,*;q=0.7"

The user agent with which this behavior was observed presented itself
with the User-Agent string: "Mozilla/5.0 (Windows; U; Windows NT 5.1;
en-US; rv:1.9) Gecko/2008052906 Firefox/3.0" Although this doesn't
appear to be correct. The request might have been mangled by a
transparent proxy.
2012-04-08 11:51:51 +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
Ali Sabil
32a46f898a Make media type parsing more relaxed
Certain user agents send slightly invalid media types, like the
following: "text/html, image/gif, image/jpeg, ; q=.2, */; q=.2"

The user agent with which this behavior was observed presented itself
with the User-Agent string: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X
10.6; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (FlipboardProxy/0.0.5;
+http://flipboard.com/browserproxy)"
2012-03-09 12:13:30 +01:00
Loïc Hoguin
d9212c21dd Remove the redundant include/ from -include("http.hrl") 2012-02-27 08:07:03 +01:00
Loïc Hoguin
a7264a1af3 Add cowboy_http:x_www_form_urlencoded/2
This was initially an internal function, it has been made public
due to popular demand as it can sometimes be needed.
2012-02-23 20:56:11 +01:00
Loïc Hoguin
f51493ee37 Add 'Expect' header parsing
At the same time renaming cowboy_http:content_type_params/3 to
cowboy_http:params/2 (with a default Acc of []) as this code isn't
useful only for content types.
2012-02-20 08:25:05 +01:00
Loïc Hoguin
16d3cb76c7 Rename the type http_status/0 to cowboy_http:status/0 2012-01-23 09:43:26 +01:00
Loïc Hoguin
a297d5e42b Rename the type http_header/0 to cowboy_http:header/0
At the same time rename http_headers/0 to cowboy_http:headers/0.
2012-01-23 09:36:59 +01:00
Loïc Hoguin
8622dff906 Rename the type http_version/0 to cowboy_http:version/0 2012-01-23 09:28:29 +01:00
Loïc Hoguin
314483a0b6 Rename the type http_uri/0 to cowboy_http:uri/0 2012-01-23 09:23:58 +01:00
Loïc Hoguin
9f40167487 Rename the type http_method/0 to cowboy_http:method/0
Exported types are much better than include files.
2012-01-23 09:21:33 +01:00
Loïc Hoguin
b650ef8907 Merge branch 'multipart' of https://github.com/nox/cowboy
Conflicts:
	src/cowboy_http_req.erl
	test/http_SUITE.erl
2012-01-23 07:37:49 +01:00
Anthony Ramine
528507c7de Add multipart support 2012-01-23 07:20:35 +01:00
Loïc Hoguin
a37dd714e0 Merge branch 'hipe-compilation-fix' of github.com:klaar/cowboy 2011-12-12 07:54:56 +01:00
Magnus Klaar
b1bbd023c5 update /bits in binary expressions to /binary
This is a workaround for an issue in the hipe compiler where
compilation of code matching on binaries using patterns of the
form Data = <<Char, _Ignore/bits>> fails because _Ignore is
expected to be used. Using /binary instead of /bits resolves
the issue.

We're applying this change to all binary expressions in cowboy_http
because all functions in this module process human readable text
formats which are always expected to be bytestrings.

Two uses of /bits has been changed to /binary in cowboy_http_websocket
in two clauses of a single function, websocket_data/4. This is safe
to change because the data is later passed to binary:match/2 which
will always fail with a badarg error if the input is a bitstring
instead of a bytestring.
2011-12-10 18:33:09 +01:00
Magnus Klaar
ef7b41c8ce add cowboy_http:urlencode/2 and urlencode/1
This function complements the cowboy_http:urldecode/2
and urldecode/1 functions. We should have this encoding
covered now. urldecode is only expected to be invoked
by user code, no further changes needed to integrate this.
2011-12-09 21:38:04 +01:00
Magnus Klaar
c747efbd75 replace quoted:from_url with cowboy_http:urldecode
This change makes the dependency on quoted optional
by adding a minimal urldecode function to cowboy.

A protocol option for setting the urldecoding function
has been added to the cowboy_http_protocol module.
The default value for this option is set to be
equivalent to the default settings for quoted.

{fun cowboy_http:urldecode/2, crash}

A note has been added in the README to document
how to use quoted instead of this function.

A field to store this option value has been added
to the state record in the cowboy_http_protocol
module and the http_req record in include/http.hrl

Functions that previously used quoted:from_url/1
has been updated to require an equivalent function
in addition to the previously required arguments.

This change removes a C compiler from the build
requirements of cowboy. It also removes the requirement
to cross compile the code if the target arch/OS
is different from the arch/OS used to build it.
2011-12-07 19:02:10 +01:00
Loïc Hoguin
83ec63374f Change the returned value for language_range parsing
Considering how it must be used, a simple binary is much better
than a tag and a list of subtags. We still parse them like this
to make sure they follow the specs, though.
2011-12-01 20:38:38 +01:00
Loïc Hoguin
2ae5e804fb Weekdays are binaries and not lists
Spotted by devinus on IRC.
2011-11-28 21:18:03 +01:00
Loïc Hoguin
f1c94c40f8 Fix specs for cowboy_http:language_range_ret/3 2011-11-24 21:32:27 +01:00
Anthony Ramine
6fa7659dbb Support 'Content-Type' in parse_header/2 2011-11-10 11:53:37 +01:00
Anthony Ramine
b184b3588d Introduce cowboy_http:media_type/2 2011-11-10 11:03:22 +01:00
Anthony Ramine
329b2fa01e Introduce cowboy_http:word/2
Used to parse either a token or a quoted string in parameters values.
2011-11-10 11:03:21 +01:00
Loïc Hoguin
2f27b046d7 Add 'If-Match' and 'If-None-Match' to parse_header/2 2011-11-09 21:41:33 +01:00
Loïc Hoguin
6dbe2b2130 Add 'Accept-Language' to cowboy_http_req:parse_header/2 2011-11-07 00:53:19 +01:00
Loïc Hoguin
3e443f0a6c Remove the IS_DIGIT macro 2011-11-05 03:23:21 +01:00