diff options
| author | Tim Watson <tim@rabbitmq.com> | 2012-10-25 12:59:11 +0100 |
|---|---|---|
| committer | Tim Watson <tim@rabbitmq.com> | 2012-10-25 12:59:11 +0100 |
| commit | c3f8d28f324fa8df99253e12ed36f6225c27cfee (patch) | |
| tree | 3e7e2c311d0cfd3167f70dd7a12bed05ff3b4ab4 /src | |
| parent | 8cdaef0b4498e295217558a763bebfb1d6dc0e02 (diff) | |
| download | rabbitmq-server-git-c3f8d28f324fa8df99253e12ed36f6225c27cfee.tar.gz | |
move invalid headers into a special 'invalid headers table' header
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_basic.erl | 23 | ||||
| -rw-r--r-- | src/rabbit_basic_tests.erl | 43 | ||||
| -rw-r--r-- | src/rabbit_tests.erl | 1 |
3 files changed, 63 insertions, 4 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl index 0e63ce1234..000a7ad86e 100644 --- a/src/rabbit_basic.erl +++ b/src/rabbit_basic.erl @@ -180,12 +180,27 @@ properties(P) when is_list(P) -> append_table_header(Name, Info, undefined) -> append_table_header(Name, Info, []); append_table_header(Name, Info, Headers) -> - Prior = case rabbit_misc:table_lookup(Headers, Name) of - {array, Existing} -> Existing; - _ -> [] - end, + case rabbit_misc:table_lookup(Headers, Name) of + {array, Existing} -> + prepend_table(Headers, Name, Info, Existing); + undefined -> + prepend_table(Headers, Name, Info, []); + Other -> + Headers2 = prepend_table(Headers, Name, Info, []), + set_invalid_header(Name, Other, Headers2) + end. + +prepend_table(Headers, Name, Info, Prior) -> rabbit_misc:set_table_value(Headers, Name, array, [{table, 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]}], + rabbit_misc:set_table_value(Headers, ?INVALID_HEADERS_KEY, + table, Invalid) + end. + extract_headers(Content) -> #content{properties = #'P_basic'{headers = Headers}} = rabbit_binary_parser:ensure_content_decoded(Content), diff --git a/src/rabbit_basic_tests.erl b/src/rabbit_basic_tests.erl new file mode 100644 index 0000000000..147e081e1a --- /dev/null +++ b/src/rabbit_basic_tests.erl @@ -0,0 +1,43 @@ +%% The contents of this file are subject to the Mozilla Public License +%% Version 1.1 (the "License"); you may not use this file except in +%% compliance with the License. You may obtain a copy of the License +%% at http://www.mozilla.org/MPL/ +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and +%% limitations under the License. +%% +%% The Original Code is RabbitMQ. +%% +%% The Initial Developer of the Original Code is VMware, Inc. +%% Copyright (c) 2007-2012 VMware, Inc. All rights reserved. +%% +-module(rabbit_basic_tests). + +-include("rabbit.hrl"). +-include_lib("eunit/include/eunit.hrl"). + +-compile(export_all). + +-define(XDEATH_TABLE, + [{<<"reason">>, longstr, <<"blah">>}, + {<<"queue">>, longstr, <<"foo.bar.baz">>}, + {<<"exchange">>, longstr, <<"my-exchange">>}, + {<<"routing-keys">>, array, []}]). + +write_table_with_invalid_existing_type_test() -> + assertInvalid(<<"x-death">>, {longstr, <<"this should be a table!!!">>}, + ?XDEATH_TABLE). + +assertInvalid(HeaderKey, {TBin, VBin}=InvalidEntry, HeaderTable) -> + Headers = rabbit_basic:append_table_header(HeaderKey, HeaderTable, + [{HeaderKey, TBin, VBin}]), + InvalidHeaders = rabbit_misc:table_lookup(Headers, ?INVALID_HEADERS_KEY), + ?assertMatch({table, _}, InvalidHeaders), + {_, Invalid} = InvalidHeaders, + InvalidArrayForKey = rabbit_misc:table_lookup(Invalid, HeaderKey), + ?assertMatch({array, _}, InvalidArrayForKey), + {_, Array} = InvalidArrayForKey, + ?assertMatch([InvalidEntry], Array). + diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index aa48f22833..6fd2dd8723 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -34,6 +34,7 @@ all_tests() -> ok = setup_cluster(), ok = supervisor2_tests:test_all(), + ok = rabbit_basic_tests:test(), passed = gm_tests:all_tests(), passed = mirrored_supervisor_tests:all_tests(), application:set_env(rabbit, file_handles_high_watermark, 10, infinity), |
