aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-01-23 09:36:59 +0100
committerLoïc Hoguin <[email protected]>2012-01-23 09:36:59 +0100
commita297d5e42b76e4d1281a1d33b54c279d8b585772 (patch)
tree23873066f4fbe5f30c9aba98319c9797aafb5007
parent8622dff906a1bdddf588e1fe006307488a824d3a (diff)
downloadcowboy-a297d5e42b76e4d1281a1d33b54c279d8b585772.tar.gz
cowboy-a297d5e42b76e4d1281a1d33b54c279d8b585772.tar.bz2
cowboy-a297d5e42b76e4d1281a1d33b54c279d8b585772.zip
Rename the type http_header/0 to cowboy_http:header/0
At the same time rename http_headers/0 to cowboy_http:headers/0.
-rw-r--r--include/http.hrl18
-rw-r--r--src/cowboy_http.erl18
-rw-r--r--src/cowboy_http_protocol.erl2
-rw-r--r--src/cowboy_http_req.erl35
4 files changed, 38 insertions, 35 deletions
diff --git a/include/http.hrl b/include/http.hrl
index e807937..40a5c6e 100644
--- a/include/http.hrl
+++ b/include/http.hrl
@@ -13,20 +13,6 @@
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
--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'
- | 'Proxy-Connection' | binary().
--type http_headers() :: list({http_header(), iodata()}).
-type http_cookies() :: list({binary(), binary()}).
-type http_status() :: non_neg_integer() | binary().
-type http_resp_body() :: iodata() | {non_neg_integer(),
@@ -53,7 +39,7 @@
qs_vals = undefined :: undefined | list({binary(), binary() | true}),
raw_qs = undefined :: undefined | binary(),
bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
- headers = [] :: http_headers(),
+ headers = [] :: cowboy_http:headers(),
p_headers = [] :: [any()], %% @todo Improve those specs.
cookies = undefined :: undefined | http_cookies(),
meta = [] :: [{atom(), any()}],
@@ -65,7 +51,7 @@
%% Response.
resp_state = waiting :: locked | waiting | chunks | done,
- resp_headers = [] :: http_headers(),
+ resp_headers = [] :: cowboy_http:headers(),
resp_body = <<>> :: http_resp_body(),
%% Functions.
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index 41c1a71..3324cd4 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -33,8 +33,22 @@
| {scheme, Scheme::binary(), binary()}
| {abs_path, binary()} | binary().
-type version() :: {Major::non_neg_integer(), Minor::non_neg_integer()}.
-
--export_type([method/0, uri/0, version/0]).
+-type 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'
+ | 'Proxy-Connection' | binary().
+-type headers() :: [{header(), iodata()}].
+
+-export_type([method/0, uri/0, version/0, header/0, headers/0]).
-include("include/http.hrl").
-include_lib("eunit/include/eunit.hrl").
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl
index 48268a1..fd987f2 100644
--- a/src/cowboy_http_protocol.erl
+++ b/src/cowboy_http_protocol.erl
@@ -158,7 +158,7 @@ wait_header(Req, State=#state{socket=Socket,
{error, closed} -> terminate(State)
end.
--spec header({http_header, integer(), http_header(), any(), binary()}
+-spec header({http_header, integer(), cowboy_http:header(), any(), binary()}
| http_eoh, #http_req{}, #state{}) -> ok | none().
header({http_header, _I, 'Host', _R, RawHost}, Req=#http_req{
transport=Transport, host=undefined}, State) ->
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 5e0c304..6555562 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -209,7 +209,7 @@ header(Name, Req, Default) when is_atom(Name) orelse is_binary(Name) ->
end.
%% @doc Return the full list of headers.
--spec headers(#http_req{}) -> {http_headers(), #http_req{}}.
+-spec headers(#http_req{}) -> {cowboy_http:headers(), #http_req{}}.
headers(Req) ->
{Req#http_req.headers, Req}.
@@ -218,7 +218,7 @@ headers(Req) ->
%% When the value isn't found, a proper default value for the type
%% returned is used as a return value.
%% @see parse_header/3
--spec parse_header(http_header(), #http_req{})
+-spec parse_header(cowboy_http:header(), #http_req{})
-> {any(), #http_req{}} | {error, badarg}.
parse_header(Name, Req=#http_req{p_headers=PHeaders}) ->
case lists:keyfind(Name, 1, PHeaders) of
@@ -227,14 +227,14 @@ parse_header(Name, Req=#http_req{p_headers=PHeaders}) ->
end.
%% @doc Default values for semantic header parsing.
--spec parse_header_default(http_header()) -> any().
+-spec parse_header_default(cowboy_http:header()) -> any().
parse_header_default('Connection') -> [];
parse_header_default(_Name) -> undefined.
%% @doc Semantically parse headers.
%%
%% When the header is unknown, the value is returned directly without parsing.
--spec parse_header(http_header(), #http_req{}, any())
+-spec parse_header(cowboy_http:header(), #http_req{}, any())
-> {any(), #http_req{}} | {error, badarg}.
parse_header(Name, Req, Default) when Name =:= 'Accept' ->
parse_header(Name, Req, Default,
@@ -414,7 +414,8 @@ body_qs(Req=#http_req{urldecode={URLDecFun, URLDecArg}}) ->
%% If the request Content-Type is not a multipart one, <em>{error, badarg}</em>
%% is returned.
-spec multipart_data(#http_req{})
- -> {{headers, http_headers()} | {data, binary()} | end_of_part | eof,
+ -> {{headers, cowboy_http:headers()}
+ | {data, binary()} | end_of_part | eof,
#http_req{}}.
multipart_data(Req=#http_req{body_state=waiting}) ->
{{<<"multipart">>, _SubType, Params}, Req2} =
@@ -477,7 +478,7 @@ set_resp_cookie(Name, Value, Options, Req) ->
set_resp_header(HeaderName, HeaderValue, Req).
%% @doc Add a header to the response.
--spec set_resp_header(http_header(), iodata(), #http_req{})
+-spec set_resp_header(cowboy_http:header(), iodata(), #http_req{})
-> {ok, #http_req{}}.
set_resp_header(Name, Value, Req=#http_req{resp_headers=RespHeaders}) ->
NameBin = header_to_binary(Name),
@@ -514,7 +515,7 @@ set_resp_body_fun(StreamLen, StreamFun, Req) ->
%% @doc Return whether the given header has been set for the response.
--spec has_resp_header(http_header(), #http_req{}) -> boolean().
+-spec has_resp_header(cowboy_http:header(), #http_req{}) -> boolean().
has_resp_header(Name, #http_req{resp_headers=RespHeaders}) ->
NameBin = header_to_binary(Name),
lists:keymember(NameBin, 1, RespHeaders).
@@ -532,12 +533,13 @@ reply(Status, Req=#http_req{resp_body=Body}) ->
reply(Status, [], Body, Req).
%% @equiv reply(Status, Headers, [], Req)
--spec reply(http_status(), http_headers(), #http_req{}) -> {ok, #http_req{}}.
+-spec reply(http_status(), cowboy_http:headers(), #http_req{})
+ -> {ok, #http_req{}}.
reply(Status, Headers, Req=#http_req{resp_body=Body}) ->
reply(Status, Headers, Body, Req).
%% @doc Send a reply to the client.
--spec reply(http_status(), http_headers(), iodata(), #http_req{})
+-spec reply(http_status(), cowboy_http:headers(), iodata(), #http_req{})
-> {ok, #http_req{}}.
reply(Status, Headers, Body, Req=#http_req{socket=Socket,
transport=Transport, connection=Connection, pid=ReqPid,
@@ -566,7 +568,7 @@ chunked_reply(Status, Req) ->
%% @doc Initiate the sending of a chunked reply to the client.
%% @see cowboy_http_req:chunk/2
--spec chunked_reply(http_status(), http_headers(), #http_req{})
+-spec chunked_reply(http_status(), cowboy_http:headers(), #http_req{})
-> {ok, #http_req{}}.
chunked_reply(Status, Headers, Req=#http_req{socket=Socket,
transport=Transport, connection=Connection, pid=ReqPid,
@@ -595,7 +597,7 @@ chunk(Data, #http_req{socket=Socket, transport=Transport, resp_state=chunks}) ->
%% @doc Send an upgrade reply.
%% @private
--spec upgrade_reply(http_status(), http_headers(), #http_req{})
+-spec upgrade_reply(http_status(), cowboy_http:headers(), #http_req{})
-> {ok, #http_req{}}.
upgrade_reply(Status, Headers, Req=#http_req{socket=Socket, transport=Transport,
pid=ReqPid, resp_state=waiting, resp_headers=RespHeaders}) ->
@@ -645,7 +647,7 @@ parse_qs(Qs, URLDecode) ->
[Name, Value] -> {URLDecode(Name), URLDecode(Value)}
end || Token <- Tokens].
--spec response_connection(http_headers(), keepalive | close)
+-spec response_connection(cowboy_http:headers(), keepalive | close)
-> keepalive | close.
response_connection([], Connection) ->
Connection;
@@ -666,8 +668,8 @@ response_connection_parse(ReplyConn) ->
Tokens = cowboy_http:nonempty_list(ReplyConn, fun cowboy_http:token/2),
cowboy_http:connection_to_atom(Tokens).
--spec response_head(http_status(), http_headers(), http_headers(),
- http_headers()) -> iolist().
+-spec response_head(http_status(), cowboy_http:headers(),
+ cowboy_http:headers(), cowboy_http:headers()) -> iolist().
response_head(Status, Headers, RespHeaders, DefaultHeaders) ->
StatusLine = <<"HTTP/1.1 ", (status(Status))/binary, "\r\n">>,
Headers2 = [{header_to_binary(Key), Value} || {Key, Value} <- Headers],
@@ -678,7 +680,8 @@ response_head(Status, Headers, RespHeaders, DefaultHeaders) ->
|| {Key, Value} <- Headers3],
[StatusLine, Headers4, <<"\r\n">>].
--spec merge_headers(http_headers(), http_headers()) -> http_headers().
+-spec merge_headers(cowboy_http:headers(), cowboy_http:headers())
+ -> cowboy_http:headers().
merge_headers(Headers, []) ->
Headers;
merge_headers(Headers, [{Name, Value}|Tail]) ->
@@ -751,7 +754,7 @@ status(507) -> <<"507 Insufficient Storage">>;
status(510) -> <<"510 Not Extended">>;
status(B) when is_binary(B) -> B.
--spec header_to_binary(http_header()) -> binary().
+-spec header_to_binary(cowboy_http:header()) -> binary().
header_to_binary('Cache-Control') -> <<"Cache-Control">>;
header_to_binary('Connection') -> <<"Connection">>;
header_to_binary('Date') -> <<"Date">>;