2011-03-07 22:59:22 +01:00
|
|
|
%% Copyright (c) 2011, Loïc Hoguin <essen@dev-extend.eu>
|
2011-05-09 14:31:06 +02:00
|
|
|
%% Copyright (c) 2011, Anthony Ramine <nox@dev-extend.eu>
|
2011-03-07 22:59:22 +01:00
|
|
|
%%
|
|
|
|
%% Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
%% purpose with or without fee is hereby granted, provided that the above
|
|
|
|
%% copyright notice and this permission notice appear in all copies.
|
|
|
|
%%
|
|
|
|
%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
2011-04-18 00:25:04 +02:00
|
|
|
-type http_header() :: 'Cache-Control' | 'Connection' | 'Date' | 'Pragma'
|
|
|
|
| 'Transfer-Encoding' | 'Upgrade' | 'Via' | 'Accept' | 'Accept-Charset'
|
|
|
|
| 'Accept-Encoding' | 'Accept-Language' | 'Authorization' | 'From' | 'Host'
|
|
|
|
| 'If-Modified-Since' | 'If-Match' | 'If-None-Match' | 'If-Range'
|
|
|
|
| 'If-Unmodified-Since' | 'Max-Forwards' | 'Proxy-Authorization' | 'Range'
|
|
|
|
| 'Referer' | 'User-Agent' | 'Age' | 'Location' | 'Proxy-Authenticate'
|
|
|
|
| 'Public' | 'Retry-After' | 'Server' | 'Vary' | 'Warning'
|
|
|
|
| 'Www-Authenticate' | 'Allow' | 'Content-Base' | 'Content-Encoding'
|
|
|
|
| 'Content-Language' | 'Content-Length' | 'Content-Location'
|
|
|
|
| 'Content-Md5' | 'Content-Range' | 'Content-Type' | 'Etag'
|
|
|
|
| 'Expires' | 'Last-Modified' | 'Accept-Ranges' | 'Set-Cookie'
|
|
|
|
| 'Set-Cookie2' | 'X-Forwarded-For' | 'Cookie' | 'Keep-Alive'
|
2011-05-05 14:03:39 +02:00
|
|
|
| 'Proxy-Connection' | binary().
|
2011-12-05 07:54:56 +01:00
|
|
|
-type http_headers() :: list({http_header(), iodata()}).
|
2011-07-08 13:41:30 -05:00
|
|
|
-type http_cookies() :: list({binary(), binary()}).
|
2011-05-05 14:03:39 +02:00
|
|
|
-type http_status() :: non_neg_integer() | binary().
|
2011-12-28 18:00:27 +01:00
|
|
|
-type http_resp_body() :: iodata() | {non_neg_integer(),
|
|
|
|
fun(() -> {sent, non_neg_integer()})}.
|
2011-04-18 00:25:04 +02:00
|
|
|
|
2011-03-07 22:59:22 +01:00
|
|
|
-record(http_req, {
|
2011-03-20 18:03:11 +01:00
|
|
|
%% Transport.
|
2011-04-18 00:06:26 +02:00
|
|
|
socket = undefined :: undefined | inet:socket(),
|
2011-03-18 22:38:26 +01:00
|
|
|
transport = undefined :: undefined | module(),
|
|
|
|
connection = keepalive :: keepalive | close,
|
2011-03-20 18:03:11 +01:00
|
|
|
|
|
|
|
%% Request.
|
2012-01-02 09:41:30 +01:00
|
|
|
pid = undefined :: pid(),
|
2012-01-23 09:21:33 +01:00
|
|
|
method = 'GET' :: cowboy_http:method(),
|
2012-01-23 09:28:29 +01:00
|
|
|
version = {1, 1} :: cowboy_http:version(),
|
2011-05-25 23:02:40 +02:00
|
|
|
peer = undefined :: undefined | {inet:ip_address(), inet:ip_port()},
|
2011-10-01 02:32:20 +02:00
|
|
|
host = undefined :: undefined | cowboy_dispatcher:tokens(),
|
|
|
|
host_info = undefined :: undefined | cowboy_dispatcher:tokens(),
|
2011-05-05 14:03:39 +02:00
|
|
|
raw_host = undefined :: undefined | binary(),
|
2011-05-25 23:02:40 +02:00
|
|
|
port = undefined :: undefined | inet:ip_port(),
|
2011-10-01 02:32:20 +02:00
|
|
|
path = undefined :: undefined | '*' | cowboy_dispatcher:tokens(),
|
|
|
|
path_info = undefined :: undefined | cowboy_dispatcher:tokens(),
|
2011-05-05 14:03:39 +02:00
|
|
|
raw_path = undefined :: undefined | binary(),
|
2011-05-25 23:02:40 +02:00
|
|
|
qs_vals = undefined :: undefined | list({binary(), binary() | true}),
|
2011-05-05 14:03:39 +02:00
|
|
|
raw_qs = undefined :: undefined | binary(),
|
2011-04-18 13:24:27 +02:00
|
|
|
bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
|
2011-03-20 18:03:11 +01:00
|
|
|
headers = [] :: http_headers(),
|
2011-10-05 03:17:13 +02:00
|
|
|
p_headers = [] :: [any()], %% @todo Improve those specs.
|
2011-07-08 13:41:30 -05:00
|
|
|
cookies = undefined :: undefined | http_cookies(),
|
2011-12-19 09:44:24 +01:00
|
|
|
meta = [] :: [{atom(), any()}],
|
2011-03-20 18:03:11 +01:00
|
|
|
|
2011-03-21 17:26:00 +01:00
|
|
|
%% Request body.
|
2011-11-08 00:51:49 +01:00
|
|
|
body_state = waiting :: waiting | done |
|
|
|
|
{multipart, non_neg_integer(), fun()},
|
2011-05-05 14:03:39 +02:00
|
|
|
buffer = <<>> :: binary(),
|
2011-03-21 17:26:00 +01:00
|
|
|
|
2011-03-20 18:03:11 +01:00
|
|
|
%% Response.
|
2011-11-28 09:09:41 +01:00
|
|
|
resp_state = waiting :: locked | waiting | chunks | done,
|
|
|
|
resp_headers = [] :: http_headers(),
|
2011-12-28 18:00:27 +01:00
|
|
|
resp_body = <<>> :: http_resp_body(),
|
2011-12-05 01:08:38 +01:00
|
|
|
|
|
|
|
%% Functions.
|
|
|
|
urldecode :: {fun((binary(), T) -> binary()), T}
|
2011-03-07 22:59:22 +01:00
|
|
|
}).
|