Skip to content

Commit c0342f9

Browse files
Philippe Le BlancqPhilippe Le Blancq
authored andcommitted
feat(soap): request_header harmonized to request_body and handle custom headers
1 parent 1834492 commit c0342f9

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/soap/request/params.ex

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule Soap.Request.Params do
2121
Returns XML-like string.
2222
"""
2323

24-
@spec build_body(wsdl :: map(), operation :: String.t() | atom(), params :: map() | tuple(), headers :: map()) ::
24+
@spec build_body(wsdl :: map(), operation :: String.t() | atom(), params :: map() | tuple(), headers :: map() | tuple()) ::
2525
String.t()
2626
def build_body(wsdl, operation, params, headers) do
2727
with {:ok, body} <- build_soap_body(wsdl, operation, params),
@@ -130,6 +130,15 @@ defmodule Soap.Request.Params do
130130
end
131131
end
132132

133+
#if first parameter is a map, bypass header wrapper and use header as is to handle multiple headers
134+
defp build_soap_header(_wsdl, _operation, [{_tag, %{} = _attrs, _nested} | _] = headers) do
135+
body =
136+
headers
137+
|> add_header_tag_wrapper
138+
139+
{:ok, body}
140+
end
141+
133142
defp build_soap_header(wsdl, operation, headers) do
134143
case headers |> construct_xml_request_header do
135144
{:error, messages} ->
@@ -181,6 +190,10 @@ defmodule Soap.Request.Params do
181190
end
182191

183192
@spec construct_xml_request_header(params :: tuple()) :: tuple()
193+
defp construct_xml_request_header({tag, attrs, nested}) do
194+
[{to_string(tag), attrs, construct_xml_request_header(nested)}]
195+
end
196+
184197
defp construct_xml_request_header(params) when is_tuple(params) do
185198
params
186199
|> Tuple.to_list()
@@ -190,8 +203,8 @@ defmodule Soap.Request.Params do
190203
end
191204

192205
@spec construct_xml_request_header(params :: String.t() | atom() | number()) :: String.t()
193-
defp construct_xml_request_header(params) when is_atom(params) or is_number(params), do: params |> to_string
194-
defp construct_xml_request_header(params) when is_binary(params), do: params
206+
defp construct_xml_request_header(params) when is_atom(params), do: params |> to_string()
207+
defp construct_xml_request_header(params) when is_binary(params) or is_number(params), do: params
195208

196209
@spec insert_tag_parameters(params :: list()) :: list()
197210
defp insert_tag_parameters(params) when is_list(params), do: params |> List.insert_at(1, nil)

0 commit comments

Comments
 (0)