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

Rename the type http_header/0 to cowboy_http:header/0

At the same time rename http_headers/0 to cowboy_http:headers/0.
This commit is contained in:
Loïc Hoguin 2012-01-23 09:36:59 +01:00
parent 8622dff906
commit a297d5e42b
4 changed files with 37 additions and 34 deletions

View file

@ -13,20 +13,6 @@
%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF %% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. %% 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_cookies() :: list({binary(), binary()}).
-type http_status() :: non_neg_integer() | binary(). -type http_status() :: non_neg_integer() | binary().
-type http_resp_body() :: iodata() | {non_neg_integer(), -type http_resp_body() :: iodata() | {non_neg_integer(),
@ -53,7 +39,7 @@
qs_vals = undefined :: undefined | list({binary(), binary() | true}), qs_vals = undefined :: undefined | list({binary(), binary() | true}),
raw_qs = undefined :: undefined | binary(), raw_qs = undefined :: undefined | binary(),
bindings = undefined :: undefined | cowboy_dispatcher:bindings(), bindings = undefined :: undefined | cowboy_dispatcher:bindings(),
headers = [] :: http_headers(), headers = [] :: cowboy_http:headers(),
p_headers = [] :: [any()], %% @todo Improve those specs. p_headers = [] :: [any()], %% @todo Improve those specs.
cookies = undefined :: undefined | http_cookies(), cookies = undefined :: undefined | http_cookies(),
meta = [] :: [{atom(), any()}], meta = [] :: [{atom(), any()}],
@ -65,7 +51,7 @@
%% Response. %% Response.
resp_state = waiting :: locked | waiting | chunks | done, resp_state = waiting :: locked | waiting | chunks | done,
resp_headers = [] :: http_headers(), resp_headers = [] :: cowboy_http:headers(),
resp_body = <<>> :: http_resp_body(), resp_body = <<>> :: http_resp_body(),
%% Functions. %% Functions.

View file

@ -33,8 +33,22 @@
| {scheme, Scheme::binary(), binary()} | {scheme, Scheme::binary(), binary()}
| {abs_path, binary()} | binary(). | {abs_path, binary()} | binary().
-type version() :: {Major::non_neg_integer(), Minor::non_neg_integer()}. -type version() :: {Major::non_neg_integer(), Minor::non_neg_integer()}.
-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]). -export_type([method/0, uri/0, version/0, header/0, headers/0]).
-include("include/http.hrl"). -include("include/http.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").

View file

@ -158,7 +158,7 @@ wait_header(Req, State=#state{socket=Socket,
{error, closed} -> terminate(State) {error, closed} -> terminate(State)
end. 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(). | http_eoh, #http_req{}, #state{}) -> ok | none().
header({http_header, _I, 'Host', _R, RawHost}, Req=#http_req{ header({http_header, _I, 'Host', _R, RawHost}, Req=#http_req{
transport=Transport, host=undefined}, State) -> transport=Transport, host=undefined}, State) ->

View file

@ -209,7 +209,7 @@ header(Name, Req, Default) when is_atom(Name) orelse is_binary(Name) ->
end. end.
%% @doc Return the full list of headers. %% @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) -> headers(Req) ->
{Req#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 %% When the value isn't found, a proper default value for the type
%% returned is used as a return value. %% returned is used as a return value.
%% @see parse_header/3 %% @see parse_header/3
-spec parse_header(http_header(), #http_req{}) -spec parse_header(cowboy_http:header(), #http_req{})
-> {any(), #http_req{}} | {error, badarg}. -> {any(), #http_req{}} | {error, badarg}.
parse_header(Name, Req=#http_req{p_headers=PHeaders}) -> parse_header(Name, Req=#http_req{p_headers=PHeaders}) ->
case lists:keyfind(Name, 1, PHeaders) of case lists:keyfind(Name, 1, PHeaders) of
@ -227,14 +227,14 @@ parse_header(Name, Req=#http_req{p_headers=PHeaders}) ->
end. end.
%% @doc Default values for semantic header parsing. %% @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('Connection') -> [];
parse_header_default(_Name) -> undefined. parse_header_default(_Name) -> undefined.
%% @doc Semantically parse headers. %% @doc Semantically parse headers.
%% %%
%% When the header is unknown, the value is returned directly without parsing. %% 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}. -> {any(), #http_req{}} | {error, badarg}.
parse_header(Name, Req, Default) when Name =:= 'Accept' -> parse_header(Name, Req, Default) when Name =:= 'Accept' ->
parse_header(Name, Req, Default, 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> %% If the request Content-Type is not a multipart one, <em>{error, badarg}</em>
%% is returned. %% is returned.
-spec multipart_data(#http_req{}) -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{}}. #http_req{}}.
multipart_data(Req=#http_req{body_state=waiting}) -> multipart_data(Req=#http_req{body_state=waiting}) ->
{{<<"multipart">>, _SubType, Params}, Req2} = {{<<"multipart">>, _SubType, Params}, Req2} =
@ -477,7 +478,7 @@ set_resp_cookie(Name, Value, Options, Req) ->
set_resp_header(HeaderName, HeaderValue, Req). set_resp_header(HeaderName, HeaderValue, Req).
%% @doc Add a header to the response. %% @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{}}. -> {ok, #http_req{}}.
set_resp_header(Name, Value, Req=#http_req{resp_headers=RespHeaders}) -> set_resp_header(Name, Value, Req=#http_req{resp_headers=RespHeaders}) ->
NameBin = header_to_binary(Name), 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. %% @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}) -> has_resp_header(Name, #http_req{resp_headers=RespHeaders}) ->
NameBin = header_to_binary(Name), NameBin = header_to_binary(Name),
lists:keymember(NameBin, 1, RespHeaders). lists:keymember(NameBin, 1, RespHeaders).
@ -532,12 +533,13 @@ reply(Status, Req=#http_req{resp_body=Body}) ->
reply(Status, [], Body, Req). reply(Status, [], Body, Req).
%% @equiv reply(Status, Headers, [], 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, Req=#http_req{resp_body=Body}) ->
reply(Status, Headers, Body, Req). reply(Status, Headers, Body, Req).
%% @doc Send a reply to the client. %% @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{}}. -> {ok, #http_req{}}.
reply(Status, Headers, Body, Req=#http_req{socket=Socket, reply(Status, Headers, Body, Req=#http_req{socket=Socket,
transport=Transport, connection=Connection, pid=ReqPid, 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. %% @doc Initiate the sending of a chunked reply to the client.
%% @see cowboy_http_req:chunk/2 %% @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{}}. -> {ok, #http_req{}}.
chunked_reply(Status, Headers, Req=#http_req{socket=Socket, chunked_reply(Status, Headers, Req=#http_req{socket=Socket,
transport=Transport, connection=Connection, pid=ReqPid, 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. %% @doc Send an upgrade reply.
%% @private %% @private
-spec upgrade_reply(http_status(), http_headers(), #http_req{}) -spec upgrade_reply(http_status(), cowboy_http:headers(), #http_req{})
-> {ok, #http_req{}}. -> {ok, #http_req{}}.
upgrade_reply(Status, Headers, Req=#http_req{socket=Socket, transport=Transport, upgrade_reply(Status, Headers, Req=#http_req{socket=Socket, transport=Transport,
pid=ReqPid, resp_state=waiting, resp_headers=RespHeaders}) -> pid=ReqPid, resp_state=waiting, resp_headers=RespHeaders}) ->
@ -645,7 +647,7 @@ parse_qs(Qs, URLDecode) ->
[Name, Value] -> {URLDecode(Name), URLDecode(Value)} [Name, Value] -> {URLDecode(Name), URLDecode(Value)}
end || Token <- Tokens]. end || Token <- Tokens].
-spec response_connection(http_headers(), keepalive | close) -spec response_connection(cowboy_http:headers(), keepalive | close)
-> keepalive | close. -> keepalive | close.
response_connection([], Connection) -> response_connection([], Connection) ->
Connection; Connection;
@ -666,8 +668,8 @@ response_connection_parse(ReplyConn) ->
Tokens = cowboy_http:nonempty_list(ReplyConn, fun cowboy_http:token/2), Tokens = cowboy_http:nonempty_list(ReplyConn, fun cowboy_http:token/2),
cowboy_http:connection_to_atom(Tokens). cowboy_http:connection_to_atom(Tokens).
-spec response_head(http_status(), http_headers(), http_headers(), -spec response_head(http_status(), cowboy_http:headers(),
http_headers()) -> iolist(). cowboy_http:headers(), cowboy_http:headers()) -> iolist().
response_head(Status, Headers, RespHeaders, DefaultHeaders) -> response_head(Status, Headers, RespHeaders, DefaultHeaders) ->
StatusLine = <<"HTTP/1.1 ", (status(Status))/binary, "\r\n">>, StatusLine = <<"HTTP/1.1 ", (status(Status))/binary, "\r\n">>,
Headers2 = [{header_to_binary(Key), Value} || {Key, Value} <- Headers], Headers2 = [{header_to_binary(Key), Value} || {Key, Value} <- Headers],
@ -678,7 +680,8 @@ response_head(Status, Headers, RespHeaders, DefaultHeaders) ->
|| {Key, Value} <- Headers3], || {Key, Value} <- Headers3],
[StatusLine, Headers4, <<"\r\n">>]. [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, []) -> merge_headers(Headers, []) ->
Headers; Headers;
merge_headers(Headers, [{Name, Value}|Tail]) -> merge_headers(Headers, [{Name, Value}|Tail]) ->
@ -751,7 +754,7 @@ status(507) -> <<"507 Insufficient Storage">>;
status(510) -> <<"510 Not Extended">>; status(510) -> <<"510 Not Extended">>;
status(B) when is_binary(B) -> B. 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('Cache-Control') -> <<"Cache-Control">>;
header_to_binary('Connection') -> <<"Connection">>; header_to_binary('Connection') -> <<"Connection">>;
header_to_binary('Date') -> <<"Date">>; header_to_binary('Date') -> <<"Date">>;