aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_protocol.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2012-09-17 12:27:42 +0200
committerLoïc Hoguin <[email protected]>2012-09-17 13:57:29 +0200
commit9090cd976553a8527d59e2638793011a3604e262 (patch)
tree2f38e80228ba32d42856c3dc222a359d116b84f9 /src/cowboy_protocol.erl
parent18be3a8021c20b9b20f919a4b59a3e8ca110c929 (diff)
downloadcowboy-9090cd976553a8527d59e2638793011a3604e262.tar.gz
cowboy-9090cd976553a8527d59e2638793011a3604e262.tar.bz2
cowboy-9090cd976553a8527d59e2638793011a3604e262.zip
Replace many proplists:get_value/{2,3} calls by BIFs
Originally suggested by Roberto Ostinelli.
Diffstat (limited to 'src/cowboy_protocol.erl')
-rw-r--r--src/cowboy_protocol.erl24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index 8020b31..f4cbed5 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -80,18 +80,26 @@ start_link(ListenerPid, Socket, Transport, Opts) ->
%% Internal.
+%% @doc Faster alternative to proplists:get_value/3.
+%% @private
+get_value(Key, Opts, Default) ->
+ case lists:keyfind(Key, 1, Opts) of
+ {_, Value} -> Value;
+ _ -> Default
+ end.
+
%% @private
-spec init(pid(), inet:socket(), module(), any()) -> ok.
init(ListenerPid, Socket, Transport, Opts) ->
- Dispatch = proplists:get_value(dispatch, Opts, []),
- MaxEmptyLines = proplists:get_value(max_empty_lines, Opts, 5),
- MaxKeepalive = proplists:get_value(max_keepalive, Opts, infinity),
- MaxLineLength = proplists:get_value(max_line_length, Opts, 4096),
- OnRequest = proplists:get_value(onrequest, Opts),
- OnResponse = proplists:get_value(onresponse, Opts),
- Timeout = proplists:get_value(timeout, Opts, 5000),
+ Dispatch = get_value(dispatch, Opts, []),
+ MaxEmptyLines = get_value(max_empty_lines, Opts, 5),
+ MaxKeepalive = get_value(max_keepalive, Opts, infinity),
+ MaxLineLength = get_value(max_line_length, Opts, 4096),
+ OnRequest = get_value(onrequest, Opts, undefined),
+ OnResponse = get_value(onresponse, Opts, undefined),
+ Timeout = get_value(timeout, Opts, 5000),
URLDecDefault = {fun cowboy_http:urldecode/2, crash},
- URLDec = proplists:get_value(urldecode, Opts, URLDecDefault),
+ URLDec = get_value(urldecode, Opts, URLDecDefault),
ok = ranch:accept_ack(ListenerPid),
wait_request(#state{listener=ListenerPid, socket=Socket, transport=Transport,
dispatch=Dispatch, max_empty_lines=MaxEmptyLines,