aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch.erl
diff options
context:
space:
mode:
authorSlava Yurin <[email protected]>2014-02-26 18:38:10 +0700
committerSlava Yurin <[email protected]>2014-06-03 18:28:15 +0700
commitbac2faea84357980ce20d5ebcaa34f0550e0447a (patch)
tree68f0ce7a2b2151083fbee5abc56af7eb6802d43f /src/ranch.erl
parentc1d0c4571ed744d4430576e171dc252937866974 (diff)
downloadranch-bac2faea84357980ce20d5ebcaa34f0550e0447a.tar.gz
ranch-bac2faea84357980ce20d5ebcaa34f0550e0447a.tar.bz2
ranch-bac2faea84357980ce20d5ebcaa34f0550e0447a.zip
Fix inherit listen options for accepted socket
Order of options in listen is undocumented but significant. Now user option will replace default value if user set it.
Diffstat (limited to 'src/ranch.erl')
-rw-r--r--src/ranch.erl27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/ranch.erl b/src/ranch.erl
index 17d24d2..c7e9727 100644
--- a/src/ranch.erl
+++ b/src/ranch.erl
@@ -120,18 +120,27 @@ set_protocol_options(Ref, Opts) ->
-spec filter_options([{atom(), any()} | {raw, any(), any(), any()}],
[atom()], Acc) -> Acc when Acc :: [any()].
-filter_options([], _, Acc) ->
- Acc;
-filter_options([Opt = {Key, _}|Tail], AllowedKeys, Acc) ->
+filter_options(UserOptions, AllowedKeys, DefaultOptions) ->
+ AllowedOptions = filter_user_options(UserOptions, AllowedKeys),
+ lists:foldl(fun merge_options/2, DefaultOptions, AllowedOptions).
+
+filter_user_options([Opt = {Key, _}|Tail], AllowedKeys) ->
case lists:member(Key, AllowedKeys) of
- true -> filter_options(Tail, AllowedKeys, [Opt|Acc]);
- false -> filter_options(Tail, AllowedKeys, Acc)
+ true -> [Opt|filter_user_options(Tail, AllowedKeys)];
+ false -> filter_user_options(Tail, AllowedKeys)
end;
-filter_options([Opt = {raw, _, _, _}|Tail], AllowedKeys, Acc) ->
+filter_user_options([Opt = {raw, _, _, _}|Tail], AllowedKeys) ->
case lists:member(raw, AllowedKeys) of
- true -> filter_options(Tail, AllowedKeys, [Opt|Acc]);
- false -> filter_options(Tail, AllowedKeys, Acc)
- end.
+ true -> [Opt|filter_user_options(Tail, AllowedKeys)];
+ false -> filter_user_options(Tail, AllowedKeys)
+ end;
+filter_user_options([], _) ->
+ [].
+
+merge_options({Key, _} = Option, OptionList) ->
+ lists:keystore(Key, 1, OptionList, Option);
+merge_options(Option, OptionList) ->
+ [Option|OptionList].
-spec set_option_default(Opts, atom(), any())
-> Opts when Opts :: [{atom(), any()}].