fix(stomp): pass the Content-Type from the MQTT message

This commit is contained in:
JianBo He 2024-04-20 08:33:55 +08:00
parent 2a2fadfbff
commit 95f3e49edb
2 changed files with 9 additions and 2 deletions

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_gateway_stomp, [ {application, emqx_gateway_stomp, [
{description, "Stomp Gateway"}, {description, "Stomp Gateway"},
{vsn, "0.1.5"}, {vsn, "0.1.6"},
{registered, []}, {registered, []},
{applications, [kernel, stdlib, emqx, emqx_gateway]}, {applications, [kernel, stdlib, emqx, emqx_gateway]},
{env, []}, {env, []},

View File

@ -1039,7 +1039,7 @@ handle_deliver(
{<<"subscription">>, Id}, {<<"subscription">>, Id},
{<<"message-id">>, next_msgid()}, {<<"message-id">>, next_msgid()},
{<<"destination">>, emqx_message:topic(NMessage)}, {<<"destination">>, emqx_message:topic(NMessage)},
{<<"content-type">>, <<"text/plain">>} {<<"content-type">>, content_type_from_mqtt_message(NMessage)}
], ],
Headers1 = Headers1 =
case Ack of case Ack of
@ -1080,6 +1080,13 @@ handle_deliver(
), ),
{ok, [{outgoing, lists:reverse(Frames0)}], Channel}. {ok, [{outgoing, lists:reverse(Frames0)}], Channel}.
content_type_from_mqtt_message(Message) ->
Properties = emqx_message:get_header(properties, Message, #{}),
case maps:get('Content-Type', Properties, undefined) of
undefined -> <<"text/plain">>;
ContentType -> ContentType
end.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Handle timeout %% Handle timeout
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------