Skip to content

Commit

Permalink
Return 204 No Content on exchange declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
ansd committed Mar 12, 2024
1 parent c0d0ad0 commit ad8595f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
24 changes: 11 additions & 13 deletions deps/rabbit/src/rabbit_amqp_management.erl
Original file line number Diff line number Diff line change
Expand Up @@ -98,22 +98,20 @@ handle_http_req(<<"PUT">>,
ok = prohibit_default_exchange(XNameBin),
XName = rabbit_misc:r(Vhost, exchange, XNameBin),
ok = check_resource_access(XName, configure, User),
{StatCode, X} = case rabbit_exchange:lookup(XName) of
{ok, FoundX} ->
{<<"200">>, FoundX};
{error, not_found} ->
ok = prohibit_cr_lf(XNameBin),
ok = prohibit_reserved_amq(XName),
X0 = rabbit_exchange:declare(
XName, XTypeAtom, Durable, AutoDelete,
Internal, XArgs, Username),
{<<"201">>, X0}
end,
X = case rabbit_exchange:lookup(XName) of
{ok, FoundX} ->
FoundX;
{error, not_found} ->
ok = prohibit_cr_lf(XNameBin),
ok = prohibit_reserved_amq(XName),
rabbit_exchange:declare(
XName, XTypeAtom, Durable, AutoDelete,
Internal, XArgs, Username)
end,
try rabbit_exchange:assert_equivalence(
X, XTypeAtom, Durable, AutoDelete, Internal, XArgs) of
ok ->
%%TODO Include the exchange in the response payload
{StatCode, [], null}
{<<"204">>, [], null}
catch exit:#amqp_error{name = precondition_failed,
explanation = Expl} ->
throw(<<"409">>, Expl, [])
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbit/src/rabbit_db_exchange.erl
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ update_in_khepri_tx(Name, Fun) ->

-spec create_or_get(Exchange) -> Ret when
Exchange :: rabbit_types:exchange(),
Ret :: {new, Exchange} | {existing, Exchange} | {error, any()}.
Ret :: {new, Exchange} | {existing, Exchange}.
%% @doc Writes an exchange record if it doesn't exist already or returns
%% the existing one.
%%
Expand Down
6 changes: 2 additions & 4 deletions deps/rabbit/src/rabbit_exchange.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ serial(X) ->
-spec declare
(name(), type(), boolean(), boolean(), boolean(),
rabbit_framing:amqp_table(), rabbit_types:username())
-> rabbit_types:exchange() | {error, term()}.
-> rabbit_types:exchange().

declare(XName, Type, Durable, AutoDelete, Internal, Args, Username) ->
X = rabbit_exchange_decorator:set(
Expand Down Expand Up @@ -123,9 +123,7 @@ declare(XName, Type, Durable, AutoDelete, Internal, Args, Username) ->
rabbit_event:notify(exchange_created, info(Exchange)),
Exchange;
{existing, Exchange} ->
Exchange;
Err ->
Err
Exchange
end;
_ ->
rabbit_log:warning("ignoring exchange.declare for exchange ~tp,
Expand Down
2 changes: 1 addition & 1 deletion deps/rabbitmq_amqp_client/src/rabbitmq_amqp_client.erl
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ declare_exchange(LinkPair, ExchangeProperties) ->
case request(LinkPair, Props, Body) of
{ok, Resp} ->
case amqp10_msg:properties(Resp) of
#{subject := <<"201">>} ->
#{subject := <<"204">>} ->
#'v1_0.amqp_value'{content = null} = amqp10_msg:body(Resp),
ok;
_ ->
Expand Down

0 comments on commit ad8595f

Please sign in to comment.