From 6ed91c9ad2b38ed9b060636a04be804d42a290be Mon Sep 17 00:00:00 2001 From: Brandon Bassett Date: Wed, 27 Mar 2019 14:15:19 -0600 Subject: [PATCH 1/7] update for elixir 1.8 --- lib/mazurka_plug.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mazurka_plug.ex b/lib/mazurka_plug.ex index 41240cf..b7e9abc 100644 --- a/lib/mazurka_plug.ex +++ b/lib/mazurka_plug.ex @@ -37,7 +37,7 @@ defmodule Mazurka.Plug do Mazurka.MissingParametersException, Mazurka.MissingRouterException] -> %{conn: conn} = err - Plug.Conn.WrapperError.reraise(conn, :error, err, System.stacktrace()) + Plug.Conn.WrapperError.reraise(conn, :error, err) end def send_resp(conn, _opts) do From b0a568d73da37d9d13e4e91121bc826ff6130af0 Mon Sep 17 00:00:00 2001 From: Brandon Bassett Date: Thu, 28 Mar 2019 16:24:46 -0600 Subject: [PATCH 2/7] put stacktrace back --- lib/mazurka_plug.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mazurka_plug.ex b/lib/mazurka_plug.ex index b7e9abc..41240cf 100644 --- a/lib/mazurka_plug.ex +++ b/lib/mazurka_plug.ex @@ -37,7 +37,7 @@ defmodule Mazurka.Plug do Mazurka.MissingParametersException, Mazurka.MissingRouterException] -> %{conn: conn} = err - Plug.Conn.WrapperError.reraise(conn, :error, err) + Plug.Conn.WrapperError.reraise(conn, :error, err, System.stacktrace()) end def send_resp(conn, _opts) do From 574401b200c2f00a8b66e66b653d8eb00a4365b8 Mon Sep 17 00:00:00 2001 From: Brandon Bassett Date: Sun, 5 May 2019 22:17:19 -0600 Subject: [PATCH 3/7] make a fallback serializer --- lib/mazurka_plug.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mazurka_plug.ex b/lib/mazurka_plug.ex index 41240cf..86a28bd 100644 --- a/lib/mazurka_plug.ex +++ b/lib/mazurka_plug.ex @@ -57,7 +57,7 @@ defmodule Mazurka.Plug do def serialize({"text", "html", _}, body) when is_tuple(body) do HTMLBuilder.encode_to_iodata!(body) end - def serialize({"text", _, _}, body) do + def serialize(_, body) do body end From 92affb54fe1552fbd4d475f6c5c1954e845355f2 Mon Sep 17 00:00:00 2001 From: Brandon Bassett Date: Sun, 5 May 2019 22:20:30 -0600 Subject: [PATCH 4/7] bump version --- mix.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index f9adf17..80f3f86 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Mazurka.Plug.Mixfile do def project do [app: :mazurka_plug, description: "Plug integration for Mazurka", - version: "0.1.6", + version: "0.1.7", elixir: "~> 1.0", build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, From db1e0bb2cde2f743b83f905afbe5334174ea97cf Mon Sep 17 00:00:00 2001 From: Michael Vanasse Date: Tue, 17 Dec 2019 18:08:41 -0700 Subject: [PATCH 5/7] point to simplecast deps --- mix.exs | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/mix.exs b/mix.exs index 80f3f86..33bcaa0 100644 --- a/mix.exs +++ b/mix.exs @@ -2,14 +2,15 @@ defmodule Mazurka.Plug.Mixfile do use Mix.Project def project do - [app: :mazurka_plug, - description: "Plug integration for Mazurka", - version: "0.1.7", - elixir: "~> 1.0", - build_embedded: Mix.env == :prod, - start_permanent: Mix.env == :prod, - package: package(), - deps: deps()] + [ + app: :mazurka_plug, + description: "Plug integration for Mazurka", + version: "0.1.7", + elixir: "~> 1.0", + build_embedded: Mix.env() == :prod, + start_permanent: Mix.env() == :prod, + deps: deps() + ] end def application do @@ -17,18 +18,13 @@ defmodule Mazurka.Plug.Mixfile do end defp deps do - [{:fugue, ">= 0.1.0"}, - {:html_builder, "~> 0.1"}, - {:mazurka, ">= 1.0.0"}, - {:plug, ">= 0.0.0"}, - {:poison, ">= 2.2.0"}, - {:ex_doc, ">= 0.0.0", only: :dev}] - end - - defp package do - [files: ["lib", "mix.exs", "README*"], - maintainers: ["Cameron Bytheway"], - licenses: ["MIT"], - links: %{"GitHub" => "https://github.com/exstruct/mazurka_plug"}] + [ + {:fugue, ">= 0.1.0"}, + {:html_builder, github: "simplecastapps/html_builder"}, + {:mazurka, github: "simplecastapps/mazurka"}, + {:plug, ">= 0.0.0"}, + {:poison, ">= 2.2.0"}, + {:ex_doc, ">= 0.0.0", only: :dev} + ] end end From a71b633677bc0917ba4654ac2b7df1b6243cc96e Mon Sep 17 00:00:00 2001 From: Michael Vanasse Date: Tue, 17 Dec 2019 18:43:45 -0700 Subject: [PATCH 6/7] formatting --- mix.exs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index 33bcaa0..0f71c1a 100644 --- a/mix.exs +++ b/mix.exs @@ -14,17 +14,19 @@ defmodule Mazurka.Plug.Mixfile do end def application do - [applications: [:logger]] + [ + applications: [:logger] + ] end defp deps do [ + {:ex_doc, ">= 0.0.0", only: :dev}, {:fugue, ">= 0.1.0"}, {:html_builder, github: "simplecastapps/html_builder"}, {:mazurka, github: "simplecastapps/mazurka"}, {:plug, ">= 0.0.0"}, - {:poison, ">= 2.2.0"}, - {:ex_doc, ">= 0.0.0", only: :dev} + {:poison, ">= 2.2.0"} ] end end From 87e314a437b93a4c5816f965e2ebfdd74bf718db Mon Sep 17 00:00:00 2001 From: Michael Vanasse Date: Thu, 19 Dec 2019 11:52:05 -0700 Subject: [PATCH 7/7] allow conns to be returned within actions and set the response body to empty on redirects --- lib/mazurka_plug.ex | 1 - lib/mazurka_plug/helpers.ex | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/mazurka_plug.ex b/lib/mazurka_plug.ex index 86a28bd..c6fb896 100644 --- a/lib/mazurka_plug.ex +++ b/lib/mazurka_plug.ex @@ -12,7 +12,6 @@ defmodule Mazurka.Plug do end end) - @doc false def action(conn, opts) when is_list(opts) do action(conn, :maps.from_list(opts)) end diff --git a/lib/mazurka_plug/helpers.ex b/lib/mazurka_plug/helpers.ex index 9693e2a..262b729 100644 --- a/lib/mazurka_plug/helpers.ex +++ b/lib/mazurka_plug/helpers.ex @@ -42,15 +42,25 @@ defmodule Mazurka.Plug.Helpers do {params, input, conn} end + def handle_body(_conn, %Plug.Conn{} = conn, content_type, serialize) do + handle_body(conn, conn.resp_body, content_type, serialize) + end + def handle_body(conn, body, {type, subtype, _} = content_type, serialize) do body = serialize.(content_type, body) %{conn | resp_body: body, state: :set} |> Conn.put_resp_content_type(type <> "/" <> subtype) end - def handle_transition(%{private: %{mazurka_transition: transition}, status: status} = conn) do - %{conn | status: status || 303} + def handle_transition(%{private: %{mazurka_transition: _} = private} = conn) do + {transition, private} = Map.pop(private, :mazurka_transition) + + %{conn | status: conn.status || 303} |> Conn.put_resp_header("location", to_string(transition)) + |> handle_transition() + end + def handle_transition(%{status: status} = conn) when status >= 300 and status < 400 do + %{conn | resp_body: ""} end def handle_transition(conn) do conn