diff options
author | Simon MacMullen <simon@rabbitmq.com> | 2012-10-29 15:57:52 +0000 |
---|---|---|
committer | Simon MacMullen <simon@rabbitmq.com> | 2012-10-29 15:57:52 +0000 |
commit | 5fcd3b58a689f93d904177ef6f1817284e7a43e7 (patch) | |
tree | ca11f0f6680bab984774bd5a9857fc96853c368c | |
parent | 3cd7676de61a14675dc47ed842ea3ff004d4f375 (diff) | |
download | rabbitmq-server-5fcd3b58a689f93d904177ef6f1817284e7a43e7.tar.gz |
Refactor a bit
-rw-r--r-- | src/rabbit_basic.erl | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl index c3e1ac99..d95ceb8c 100644 --- a/src/rabbit_basic.erl +++ b/src/rabbit_basic.erl @@ -196,30 +196,25 @@ prepend_table(Headers, Name, Info, Prior) -> set_invalid_header(Name, {_, _}=Value, Headers) when is_list(Headers) -> case rabbit_misc:table_lookup(Headers, ?INVALID_HEADERS_KEY) of undefined -> - Invalid = [{Name, array, [Value]}], - set_invalid(Headers, Invalid); - {table, InvalidEntries} -> - case rabbit_misc:table_lookup(InvalidEntries, Name) of - undefined -> - set_invalid(Headers, InvalidEntries, Name, [Value]); - {array, Prior} -> - set_invalid(Headers, InvalidEntries, Name, [Value | Prior]) - end; + set_invalid(Headers, [{Name, array, [Value]}]); + {table, ExistingHdr} -> + update_invalid(Headers, ExistingHdr, Name, Value); Other -> %% somehow the x-invalid-headers header is corrupt Invalid = [{?INVALID_HEADERS_KEY, array, [Other]}], set_invalid_header(Name, Value, set_invalid(Headers, Invalid)) end. -set_invalid(Headers, Invalid) -> - rabbit_misc:set_table_value(Headers, ?INVALID_HEADERS_KEY, - table, Invalid). +set_invalid(Headers, NewHdr) -> + rabbit_misc:set_table_value(Headers, ?INVALID_HEADERS_KEY, table, NewHdr). -set_invalid(Headers, InvalidEntries, Name, Values) -> - rabbit_misc:set_table_value( - Headers, ?INVALID_HEADERS_KEY, table, - rabbit_misc:set_table_value(InvalidEntries, - Name, array, Values)). +update_invalid(Headers, ExistingHdr, Name, Value) -> + Values = case rabbit_misc:table_lookup(ExistingHdr, Name) of + undefined -> [Value]; + {array, Prior} -> [Value | Prior] + end, + NewHdr = rabbit_misc:set_table_value(ExistingHdr, Name, array, Values), + set_invalid(Headers, NewHdr). extract_headers(Content) -> #content{properties = #'P_basic'{headers = Headers}} = |