diff --git a/lib/aws_codegen/rest_service.ex b/lib/aws_codegen/rest_service.ex index 02d2e50..c9f3795 100644 --- a/lib/aws_codegen/rest_service.ex +++ b/lib/aws_codegen/rest_service.ex @@ -256,6 +256,9 @@ defmodule AWS.CodeGen.RestService do function_name = AWS.CodeGen.Name.to_snake_case(operation) request_header_parameters = collect_request_header_parameters(language, api_spec, operation) + request_headers_parameters = + collect_request_headers_parameters(language, api_spec, operation) + is_required = fn param -> param.required end required_query_parameters = Enum.filter(query_parameters, is_required) required_request_header_parameters = Enum.filter(request_header_parameters, is_required) @@ -266,7 +269,8 @@ defmodule AWS.CodeGen.RestService do "GET" -> case language do :elixir -> - 2 + length(request_header_parameters) + length(query_parameters) + 2 + length(request_header_parameters) + length(request_headers_parameters) + + length(query_parameters) :erlang -> 4 + length(required_request_header_parameters) + length(required_query_parameters) @@ -295,6 +299,7 @@ defmodule AWS.CodeGen.RestService do query_parameters: query_parameters, required_query_parameters: required_query_parameters, request_header_parameters: request_header_parameters, + request_headers_parameters: request_headers_parameters, required_request_header_parameters: required_request_header_parameters, response_header_parameters: collect_response_header_parameters(language, api_spec, operation), @@ -338,6 +343,10 @@ defmodule AWS.CodeGen.RestService do collect_parameters(language, api_spec, operation, "input", "smithy.api#httpHeader") end + defp collect_request_headers_parameters(language, api_spec, operation) do + collect_parameters(language, api_spec, operation, "input", "smithy.api#httpPrefixHeaders") + end + defp collect_response_header_parameters(language, api_spec, operation) do collect_parameters(language, api_spec, operation, "output", "smithy.api#httpHeader") end diff --git a/priv/rest.ex.eex b/priv/rest.ex.eex index 0bf88e3..bc6ed0a 100644 --- a/priv/rest.ex.eex +++ b/priv/rest.ex.eex @@ -124,7 +124,13 @@ def <%= action.function_name %>(%Client{} = client<%= AWS.CodeGen.RestService.fu {"<%= parameter.name %>", "<%= parameter.location_name %>"},<% end %> ] |> Request.build_params(input)<% else %> - headers = []<% end %><%= if length(action.query_parameters) > 0 do %> + headers = []<% end %><%= if length(action.request_headers_parameters) > 0 do %> + {custom_headers, input} = + [<%= for parameter <- action.request_headers_parameters do %> + {"<%= parameter.name %>", "<%= parameter.location_name %>"},<% end %> + ] + |> Request.build_params(input)<% else %> + custom_headers = []<% end %><%= if length(action.query_parameters) > 0 do %> {query_params, input} = [<%= for parameter <- action.query_parameters do %> {"<%= parameter.name %>", "<%= parameter.location_name %>"},<% end %> @@ -168,6 +174,6 @@ def <%= action.function_name %>(%Client{} = client<%= AWS.CodeGen.RestService.fu metadata() <% end %> - Request.request_rest(client, meta, <%= AWS.CodeGen.RestService.Action.method(action) %>, url_path, query_params, headers, input, options, <%= inspect(action.success_status_code) %>)<% end %> + Request.request_rest(client, meta, <%= AWS.CodeGen.RestService.Action.method(action) %>, url_path, query_params, custom_headers ++ headers, input, options, <%= inspect(action.success_status_code) %>)<% end %> end<% end %> end