No function clause matching in anonymous fn/2 in Plug.Conn.merge_resp_headers/2

Hi all

I try to merge response header via the merge_resp_headers(conn, headers) from plug and got following error:

[info] GET /odata/InsCharInfoSet
[debug] Processing with WpAdmin.Web.OdataController.get/2
  Parameters: %{"uri" => "InsCharInfoSet"}
  Pipelines: [:api]
[info] Sent 500 in 329ms
[error] #PID<0.391.0> running WpAdmin.Web.Endpoint terminated
Server: localhost:4000 (http)
Request: GET /odata/InsCharInfoSet
** (exit) an exception was raised:
    ** (FunctionClauseError) no function clause matching in anonymous fn/2 in Plug.Conn.merge_resp_headers/2
        (plug) lib/plug/conn.ex:631: anonymous fn({"set-cookie", ["SAP_SESSIONID_D58_295=dj5kjI2pdbHBWb8M8Y81dTJX4zMEHhHnkO5SVABnURs%3d; path=/", "MYSAPSSO2=AjQxMDMBABhCAE0AQQAgACAAIAAgACAAIAAgACAAIAACAAYyADkANQADABBEADUAOAAgACAAIAAgACAABAAYMgAwADEANwAwADMAMAA4ADEANgA0ADIABQAEAAAACAYAAlgACQACRAD%2fAVcwggFTBgkqhkiG9w0BBwKgggFEMIIBQAIBATELMAkGBSsOAwIaBQAwCwYJKoZIhvcNAQcBMYIBHzCCARsCAQEwbzBkMQswCQYDVQQGEwJERTEcMBoGA1UEChMTU0FQIFRydXN0IENvbW11bml0eTETMBEGA1UECxMKU0FQIFdlYiBBUzEUMBIGA1UECxMLSTAwMjAwODc3MzIxDDAKBgNVBAMTA0Q1OAIHIBEBFxMEEzAJBgUrDgMCGgUAoF0wGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAcBgkqhkiG9w0BCQUxDxcNMTcwMzA4MTY0MjE5WjAjBgkqhkiG9w0BCQQxFgQUrbVlMroBri74cmPW2%2f%2fFWFOoksgwCQYHKoZIzjgEAwQwMC4CFQCMPsKm%2fZxNnp1xsY2gIJi9KFtYLwIVAJPn%2fs2oH054mcMaDpPGJ3FKXd01; path=/; domain=.example.ch"]}, [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "311lh5fv6votvvcfpjdbd0buk0gl5abl"}, {"content-length", "4721"}, {"content-type", "application/json; charset=utf-8"}, {"dataserviceversion", "2.0"}]) in Plug.Conn.merge_resp_headers/2
        (elixir) lib/enum.ex:1755: Enum."-reduce/3-lists^foldl/2-0-"/3
        (plug) lib/plug/conn.ex:631: Plug.Conn.merge_resp_headers/2
        (wp_admin) lib/wp_admin/web/controllers/odata_controller.ex:16: WpAdmin.Web.OdataController.get/2
        (wp_admin) lib/wp_admin/web/controllers/odata_controller.ex:1: WpAdmin.Web.OdataController.action/2
        (wp_admin) lib/wp_admin/web/controllers/odata_controller.ex:1: WpAdmin.Web.OdataController.phoenix_controller_pipeline/2
        (wp_admin) lib/wp_admin/web/endpoint.ex:1: WpAdmin.Web.Endpoint.instrument/4
        (phoenix) lib/phoenix/router.ex:277: Phoenix.Router.__call__/1
        (wp_admin) lib/wp_admin/web/endpoint.ex:1: WpAdmin.Web.Endpoint.plug_builder_call/2
        (wp_admin) lib/plug/debugger.ex:123: WpAdmin.Web.Endpoint."call (overridable 3)"/2
        (wp_admin) lib/wp_admin/web/endpoint.ex:1: WpAdmin.Web.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) /home/anujit/elixir/wp/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

The action in the controller looks as follow:

defmodule WpAdmin.Web.OdataController do

  use WpAdmin.Web, :controller

  alias WpOdata.Sap.Request
  alias WpOdata.Protocols.Query
  import Plug.Conn

  def get(conn, %{"uri" => uri}) do

    accept_header = get_req_header(conn, "accept")
    req = %Request{uri: uri, basic_auth: "Basic 0000000000000", headers: ["accept": accept_header]}
    {status_code, body, headers} = Query.get(req)
    list_headers = Enum.into(headers, [])

    conn
    |> Plug.Conn.merge_resp_headers(list_headers)
    |> send_resp(status_code, body)

  end

end

What am I doing wrong?

Thanks

1 Like