aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Burdick <[email protected]>2011-07-18 15:50:29 -0500
committerLoïc Hoguin <[email protected]>2011-07-26 13:53:52 +0200
commitb75859e07511fc07954542872dd18548f3f7d4fc (patch)
treeb92fab7616a28eeb3aa98b34665f0ec4467cb879
parent5bd936db6606a27dfd91a0e2675889b58c212376 (diff)
downloadcowboy-b75859e07511fc07954542872dd18548f3f7d4fc.tar.gz
cowboy-b75859e07511fc07954542872dd18548f3f7d4fc.tar.bz2
cowboy-b75859e07511fc07954542872dd18548f3f7d4fc.zip
Fail early in cookie-related API functions
-rw-r--r--src/cowboy_cookies.erl6
-rw-r--r--src/cowboy_http_req.erl4
2 files changed, 5 insertions, 5 deletions
diff --git a/src/cowboy_cookies.erl b/src/cowboy_cookies.erl
index acaefee..8a11b19 100644
--- a/src/cowboy_cookies.erl
+++ b/src/cowboy_cookies.erl
@@ -43,17 +43,17 @@
-spec parse_cookie(binary()) -> kvlist().
parse_cookie(<<>>) ->
[];
-parse_cookie(Cookie) ->
+parse_cookie(Cookie) when is_binary(Cookie) ->
parse_cookie(Cookie, []).
%% @doc Short-hand for <code>cookie(Key, Value, [])</code>.
-spec cookie(binary(), binary()) -> kvlist().
-cookie(Key, Value) ->
+cookie(Key, Value) when is_binary(Key) andalso is_binary(Value) ->
cookie(Key, Value, []).
%% @doc Generate a Set-Cookie header field tuple.
-spec cookie(binary(), binary(), [cookie_option()]) -> kvlist().
-cookie(Key, Value, Options) ->
+cookie(Key, Value, Options) when is_binary(Key) andalso is_binary(Value) andalso is_list(Options) ->
Cookie = <<(any_to_binary(Key))/binary, "=", (quote(Value))/binary, "; Version=1">>,
%% Set-Cookie:
%% Comment, Domain, Max-Age, Path, Secure, Version
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 323f750..69d47b0 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -181,14 +181,14 @@ headers(Req) ->
%% @equiv cookie(Name, Req, undefined)
-spec cookie(binary(), #http_req{})
-> {binary() | true | undefined, #http_req{}}.
-cookie(Name, Req) ->
+cookie(Name, Req) when is_binary(Name) ->
cookie(Name, Req, undefined).
%% @doc Return the cookie value for the given key, or a default if
%% missing.
-spec cookie(binary(), #http_req{}, Default)
-> {binary() | true | Default, #http_req{}} when Default::any().
-cookie(Name, Req=#http_req{cookies=undefined}, Default) ->
+cookie(Name, Req=#http_req{cookies=undefined}, Default) when is_binary(Name) ->
case header('Cookie', Req) of
{undefined, Req2} ->
{Default, Req2#http_req{cookies=[]}};