diff options
author | Slava Yurin <[email protected]> | 2014-02-26 18:38:10 +0700 |
---|---|---|
committer | Slava Yurin <[email protected]> | 2014-06-03 18:28:15 +0700 |
commit | bac2faea84357980ce20d5ebcaa34f0550e0447a (patch) | |
tree | 68f0ce7a2b2151083fbee5abc56af7eb6802d43f /src | |
parent | c1d0c4571ed744d4430576e171dc252937866974 (diff) | |
download | ranch-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')
-rw-r--r-- | src/ranch.erl | 27 |
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()}]. |