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

Fix typespecs for cowboy_req:binding/{2,3} and :bindings/1

This commit is contained in:
Loïc Hoguin 2013-12-28 20:10:06 +01:00
parent 6907541a78
commit 7a274661b2
2 changed files with 13 additions and 5 deletions

View file

@ -49,17 +49,25 @@ Request related exports
> Types: > Types:
> * Name = atom() > * Name = atom()
> * Default = any() > * Default = any()
> * Value = binary() | Default > * Value = any() | Default
> >
> Return the value for the given binding. > Return the value for the given binding.
>
> By default the value is a binary, however constraints may change
> the type of this value (for example automatically converting
> numbers to integer).
### bindings(Req) -> {[{Name, Value}], Req2} ### bindings(Req) -> {[{Name, Value}], Req2}
> Types: > Types:
> * Name = atom() > * Name = atom()
> * Value = binary() > * Value = any()
> >
> Return all bindings. > Return all bindings.
>
> By default the value is a binary, however constraints may change
> the type of this value (for example automatically converting
> numbers to integer).
### cookie(Name, Req) -> cookie(Name, Req, undefined) ### cookie(Name, Req) -> cookie(Name, Req, undefined)
### cookie(Name, Req, Default) -> {Value, Req2} ### cookie(Name, Req, Default) -> {Value, Req2}

View file

@ -334,14 +334,14 @@ url(HostURL, Req=#http_req{path=Path, qs=QS}) ->
{<< HostURL/binary, Path/binary, QS2/binary >>, Req}. {<< HostURL/binary, Path/binary, QS2/binary >>, Req}.
%% @equiv binding(Name, Req, undefined) %% @equiv binding(Name, Req, undefined)
-spec binding(atom(), Req) -> {binary() | undefined, Req} when Req::req(). -spec binding(atom(), Req) -> {any() | undefined, Req} when Req::req().
binding(Name, Req) when is_atom(Name) -> binding(Name, Req) when is_atom(Name) ->
binding(Name, Req, undefined). binding(Name, Req, undefined).
%% @doc Return the binding value for the given key obtained when matching %% @doc Return the binding value for the given key obtained when matching
%% the host and path against the dispatch list, or a default if missing. %% the host and path against the dispatch list, or a default if missing.
-spec binding(atom(), Req, Default) -spec binding(atom(), Req, Default)
-> {binary() | Default, Req} when Req::req(), Default::any(). -> {any() | Default, Req} when Req::req(), Default::any().
binding(Name, Req, Default) when is_atom(Name) -> binding(Name, Req, Default) when is_atom(Name) ->
case lists:keyfind(Name, 1, Req#http_req.bindings) of case lists:keyfind(Name, 1, Req#http_req.bindings) of
{Name, Value} -> {Value, Req}; {Name, Value} -> {Value, Req};
@ -349,7 +349,7 @@ binding(Name, Req, Default) when is_atom(Name) ->
end. end.
%% @doc Return the full list of binding values. %% @doc Return the full list of binding values.
-spec bindings(Req) -> {list({atom(), binary()}), Req} when Req::req(). -spec bindings(Req) -> {[{atom(), any()}], Req} when Req::req().
bindings(Req) -> bindings(Req) ->
{Req#http_req.bindings, Req}. {Req#http_req.bindings, Req}.