summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Watson <tim@rabbitmq.com>2012-10-25 12:59:11 +0100
committerTim Watson <tim@rabbitmq.com>2012-10-25 12:59:11 +0100
commit0ea5176dbbe182cac2c1b6fd6fe751a79c72af87 (patch)
tree3e7e2c311d0cfd3167f70dd7a12bed05ff3b4ab4
parent4e1b30e6080810bd375b30a1d55f6647bb446166 (diff)
downloadrabbitmq-server-0ea5176dbbe182cac2c1b6fd6fe751a79c72af87.tar.gz
move invalid headers into a special 'invalid headers table' header
-rw-r--r--include/rabbit.hrl1
-rw-r--r--src/rabbit_basic.erl23
-rw-r--r--src/rabbit_basic_tests.erl43
-rw-r--r--src/rabbit_tests.erl1
4 files changed, 64 insertions, 4 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl
index 3db2b68a..dc99bf78 100644
--- a/include/rabbit.hrl
+++ b/include/rabbit.hrl
@@ -101,5 +101,6 @@
-define(DESIRED_HIBERNATE, 10000).
-define(CREDIT_DISC_BOUND, {2000, 500}).
+-define(INVALID_HEADERS_KEY, <<"x-invalid-headers">>).
-define(ROUTING_HEADERS, [<<"CC">>, <<"BCC">>]).
-define(DELETED_HEADER, <<"BCC">>).
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl
index 0e63ce12..000a7ad8 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 00000000..147e081e
--- /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 aa48f228..6fd2dd87 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),