From 0292a7922554b62115890c92d8dd989a95631cbe Mon Sep 17 00:00:00 2001 From: Alexey Nikitin Date: Fri, 11 Aug 2023 00:56:29 +0400 Subject: [PATCH] Do not modify conn for pattern-matching purpose. Use different function name instead Conn struct can be used further in origin detection when fun with arity 1 is passed --- lib/cors_plug.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/cors_plug.ex b/lib/cors_plug.ex index 3842a6a..51438f5 100644 --- a/lib/cors_plug.ex +++ b/lib/cors_plug.ex @@ -35,12 +35,12 @@ defmodule CORSPlug do {true, "OPTIONS", _} -> conn - |> merge_resp_headers(add_cors_headers(conn, options)) + |> merge_resp_headers(add_cors_headers_options(conn, options)) |> send_resp(204, "") |> halt() {false, "OPTIONS", _} -> - merge_resp_headers(conn, add_cors_headers(conn, options)) + merge_resp_headers(conn, add_cors_headers_options(conn, options)) {_, _, _} -> merge_resp_headers(conn, add_cors_headers(conn, options)) @@ -62,8 +62,8 @@ defmodule CORSPlug do end # headers specific to OPTIONS request - defp add_cors_headers(conn = %Plug.Conn{method: "OPTIONS"}, options) do - add_cors_headers(%{conn | method: nil}, options) ++ + defp add_cors_headers_options(conn, options) do + add_cors_headers(conn, options) ++ [ {"access-control-max-age", "#{options[:max_age]}"}, {"access-control-allow-headers", allowed_headers(options[:headers], conn)},