aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2011-03-27 13:11:57 +0200
committerLoïc Hoguin <[email protected]>2011-03-27 13:11:57 +0200
commit150723ca21e3b23ea0d4341d7775a3d03e78e9eb (patch)
treed819fd949b4702944f3ddf92835553d63e5fe0e4 /src
parentd0d9b0e8b363b456bd0b9e5fbdebc90f055546c3 (diff)
downloadcowboy-150723ca21e3b23ea0d4341d7775a3d03e78e9eb.tar.gz
cowboy-150723ca21e3b23ea0d4341d7775a3d03e78e9eb.tar.bz2
cowboy-150723ca21e3b23ea0d4341d7775a3d03e78e9eb.zip
Return undefined instead of failing or returning "" when a value doesn't exist.
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_req.erl20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/cowboy_http_req.erl b/src/cowboy_http_req.erl
index 73db521..8d558b7 100644
--- a/src/cowboy_http_req.erl
+++ b/src/cowboy_http_req.erl
@@ -71,13 +71,15 @@ raw_path(Req) ->
{Req#http_req.raw_path, Req}.
-spec qs_val(Name::string(), Req::#http_req{})
- -> {Value::string() | true, Req::#http_req{}}.
+ -> {Value::string() | true | undefined, Req::#http_req{}}.
qs_val(Name, Req=#http_req{raw_qs=RawQs, qs_vals=undefined}) ->
QsVals = parse_qs(RawQs),
qs_val(Name, Req#http_req{qs_vals=QsVals});
qs_val(Name, Req) ->
- {Name, Value} = lists:keyfind(Name, 1, Req#http_req.qs_vals),
- {Value, Req}.
+ case lists:keyfind(Name, 1, Req#http_req.qs_vals) of
+ {Name, Value} -> {Value, Req};
+ false -> {undefined, Req}
+ end.
-spec qs_val(Name::string(), Default::term(), Req::#http_req{})
-> {Value::string() | term() | true, Req::#http_req{}}.
@@ -101,10 +103,12 @@ raw_qs(Req) ->
{Req#http_req.raw_qs, Req}.
-spec binding(Name::atom(), Req::#http_req{})
- -> {Value::string(), Req::#http_req{}}.
+ -> {Value::string() | undefined, Req::#http_req{}}.
binding(Name, Req) ->
- {Name, Value} = lists:keyfind(Name, 1, Req#http_req.bindings),
- {Value, Req}.
+ case lists:keyfind(Name, 1, Req#http_req.bindings) of
+ {Name, Value} -> {Value, Req};
+ false -> {undefined, Req}
+ end.
-spec binding(Name::atom(), Default::term(), Req::#http_req{})
-> {Value::string() | term(), Req::#http_req{}}.
@@ -118,11 +122,11 @@ bindings(Req) ->
{Req#http_req.bindings, Req}.
-spec header(Name::atom() | string(), Req::#http_req{})
- -> {Value::string(), Req::#http_req{}}.
+ -> {Value::string() | undefined, Req::#http_req{}}.
header(Name, Req) ->
case lists:keyfind(Name, 1, Req#http_req.headers) of
{Name, Value} -> {Value, Req};
- false -> {"", Req}
+ false -> {undefined, Req}
end.
-spec header(Name::atom() | string(), Default::term(), Req::#http_req{})