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

51 commits

Author SHA1 Message Date
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
Loïc Hoguin
3885912d9b Rename inet:ip_port() to inet:port_number()
Thanks go to @superbobry for pointing it out.
2012-03-12 21:57:07 +01:00
Loïc Hoguin
7b359352d4 Remove http_resp_body/0, inline it directly in the record definition 2012-01-23 09:46:40 +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
67e5713b2b Remove http_cookies/0, inline it directly in the record definition 2012-01-23 09:39:17 +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
fd211d3c03 Fix handler crashes handling
We try to send a 500 error only if we didn't send the response
headers yet. If they were, then we have no way to be sure the
response was fully sent, nor should we assume anything about
how this will be handled client-side, so we do nothing more
and in both cases close the connection.
2012-01-06 20:23:59 +01:00
Magnus Klaar
937a2b0326 Add cowboy_http_req:set_resp_body_fun/3. 2011-12-28 18:17:10 +01:00
Loïc Hoguin
f390dbd606 Add meta/2 and meta/3 to cowboy_http_req to save useful protocol information
* cowboy_http_protocol now defines 'websocket_version' as metadata.
* cowboy_http_rest now defines 'media_type', 'language', 'charset' as metadata.
2011-12-19 09:44:47 +01:00
Magnus Klaar
fed1410b14 update type of resp_body to iodata
resp_body is set by cowboy_http_req:set_resp_body/2 which accepts
the input type iodata(). Update the resp_body field to use the same
type. Also update the cowboy_http_req:has_resp_body/2 function to
use the iolist_size/1 which works with both binary() and iolist()
values instead of the byte_size/1 function which only works with
binary() values.
2011-12-16 16:29:13 +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
99d8f837fe Fix specs to allow headers as iodata() and not just binary() 2011-12-05 07:54:56 +01:00
Loïc Hoguin
64a40cb479 Add set_resp_header/3 and set_resp_body/2 to cowboy_http_req
These functions allow to set response headers and body in advance,
before calling any of the reply functions.

Also add has_resp_header/2 and has_resp_body/1 to check if the given
response headers have already been set.
2011-11-28 09:09:41 +01:00
Loïc Hoguin
138cccb4f9 Allow HTTP handlers to skip the handle/2 step in init/3
You can now return {shutdown, Req, State} from Handler:init/3
to skip the handle/2 step.

Also allow init/3 function to send responses.
2011-10-06 15:54:37 +02:00
Loïc Hoguin
bf5c2717bc Parse 'Connection' headers as a list of tokens
Replaces the 'Connection' interpretation in cowboy_http_protocol
from raw value to the parsed value, looking for a single token
matching close/keep-alive instead of the whole raw value (which
could contain more than one token, for example with Firefox 6+
using websocket).

Introduce the functions cowboy_http_req:parse_header/2 and /3
to semantically parse the header values and return a proper
Erlang term.
2011-10-05 13:32:20 +02:00
Loïc Hoguin
ce26d7090b Rename the type cowboy_dispatcher:path_tokens/0 to :tokens/0 2011-10-01 02:32:20 +02:00
Tom Burdick
5bd936db66 Implement cookies in cowboy_http_req 2011-07-26 13:53:31 +02:00
Loïc Hoguin
3e55cb62c9 Refresh the type specifications.
Following discussions on #erlounge.

Also fixes compilation in R14B03 and fixes a few underspecs
dialyzer warnings.
2011-05-25 23:02:40 +02:00
Anthony Ramine
0ca8f1364b Implement path_info feature
The dispatcher now accepts '...' as the leading segment of Host and the
trailing segment of Path, this special atom matches any remaining path tail.

When given "cowboy.bugs.dev-extend.eu", host rule ['...', <<"dev-extend">>,
<<"eu">>] matches and fills host_info with [<<"cowboy">>, <<"bugs">>].

When given "/a/b/c/d", path rule [<<"a">>, <<"b">>, '...'] matches and fills
path_info with [<<"c">>, <<"d">>].
2011-05-09 15:14:38 +02:00
Loïc Hoguin
420f5baf98 Add chunked reply support.
Send the status line and headers using
cowboy_http_req:chunked_reply/3, and
individual chunks with cowboy_http_req:chunk/2.
2011-05-08 17:26:21 +02:00
Loïc Hoguin
29e71cf4da Switch the HTTP protocol to use binary packets instead of lists.
The server now does a single recv (or more, but only if needed)
which is then sent to erlang:decode_packet/3 multiple times. Since
most requests are smaller than the default MTU on many platforms,
we benefit from this greatly.

In the case of requests with a body, the server usually read at
least part of the body on the first recv. This is bufferized
properly and used when later retrieving the body.

In the case of pipelined requests, we can end up reading many
requests in a single recv, which are then handled properly using
only the buffer containing the received data.
2011-05-05 14:03:39 +02:00
Loïc Hoguin
6c1f73c53c Add cowboy_http_req:port/1.
Returns the port given in the Host header if present,
otherwise the default port of 443 for HTTPS and 80 for HTTP
is returned.
2011-05-04 12:52:13 +02:00
Loïc Hoguin
e8286e18e6 Remove the include/types.hrl file. 2011-04-18 13:56:38 +02:00
Loïc Hoguin
63a92df14e Replace port_number() by ip_port() from kernel/include/inet.hrl. 2011-04-18 13:52:32 +02:00
Loïc Hoguin
731d839323 Replace posix() by atom(), for now.
The type isn't exported by OTP so we don't win much.
Also, inet.erl and file.erl define posix() différently,
so OTP needs to stop being so confuse in the first place
before we can attempt to use it properly.
2011-04-18 13:32:35 +02:00
Loïc Hoguin
db7833f5e8 Move the type application_start_type() into cowboy_app. 2011-04-18 13:27:42 +02:00
Loïc Hoguin
2beb5c8206 Move the dispatcher related types into cowboy_dispatcher. 2011-04-18 13:24:27 +02:00
Loïc Hoguin
6712eaa5c8 Rename match() into match_rule(). 2011-04-18 12:20:52 +02:00
Loïc Hoguin
ef2673b61e Rename dispatch() into dispatch_rules(). 2011-04-18 12:14:13 +02:00
Loïc Hoguin
ecf117b375 Rename dispatch_rules() into dispatch_rule(). 2011-04-18 12:06:53 +02:00
Loïc Hoguin
02d825e003 Move HTTP types definitions to include/http.hrl (for now). 2011-04-18 00:25:04 +02:00
Loïc Hoguin
61d755f8cc Move the opaque type sslsocket() out of include/types.hrl. 2011-04-18 00:09:12 +02:00
Loïc Hoguin
15dc645596 Use the inet:socket() type instead of the user-defined one. 2011-04-18 00:06:26 +02:00
Loïc Hoguin
9ad32386c0 Use the inet:ip_address() type instead of the user-defined one. 2011-04-17 23:57:30 +02:00
Loïc Hoguin
c285f00349 Fix the type spec for qs_vals, a list of key/values. 2011-03-27 01:07:01 +01:00
Loïc Hoguin
d4c071c2d0 Fix the type spec for path_tokens, a list of *non empty* strings. 2011-03-22 12:26:07 +01:00
Loïc Hoguin
0c0b75f76b Fix spec for the #http_spec.path record field. 2011-03-21 22:32:02 +01:00
Loïc Hoguin
193968d53e Fix spec for cowboy_dispatcher:split_host/1. 2011-03-21 22:13:27 +01:00
Loïc Hoguin
8b02992e6a Skip the request body if it hasn't been read by the handler. 2011-03-21 17:47:17 +01:00
Loïc Hoguin
71b31cee92 Make sure we can only reply to an HTTP request inside Handler:handle.
Of course since requests are a record the response state can be explicitly
overriden, but standard use prevents errors by making sure only one reply
is sent.
2011-03-20 18:03:36 +01:00
Loïc Hoguin
b874b28561 Save the raw path string in the request. 2011-03-20 00:01:29 +01:00
Loïc Hoguin
8085529f48 Save the raw host string in the request. 2011-03-19 23:57:23 +01:00
Loïc Hoguin
a4f8bb6573 Add support for the '*' path.
Mostly used by the following request: OPTIONS * HTTP/1.1
2011-03-19 18:53:59 +01:00
Loïc Hoguin
2c52a30b0a Rewrite the dispatcher to take a list of host each having a list of paths.
* Makes more sense to parse the host only once instead of for each path.
* Allows proper handling of: If the host is not a valid host on the server,
  the response MUST be a 400 (Bad Request) error.
2011-03-19 17:42:03 +01:00
Loïc Hoguin
408f167621 Move the reply function to cowboy_http_req. 2011-03-18 22:38:26 +01:00