From 51b701111a3b33601980703417388cd099dc7e44 Mon Sep 17 00:00:00 2001 From: Daniel Khaapamyaki Date: Thu, 31 Mar 2022 21:35:21 +0200 Subject: [PATCH] Set response header content-type charset to nil --- lib/twirp/plug.ex | 4 ++-- test/twirp/plug_test.exs | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/twirp/plug.ex b/lib/twirp/plug.ex index 7ee4cb9..4d05491 100644 --- a/lib/twirp/plug.ex +++ b/lib/twirp/plug.ex @@ -105,7 +105,7 @@ defmodule Twirp.Plug do Telemetry.stop(:call, start, metadata) conn - |> put_resp_content_type(env.content_type) + |> put_resp_content_type(env.content_type, nil) |> send_resp(200, resp) |> halt() else @@ -283,7 +283,7 @@ defmodule Twirp.Plug do body = Encoder.encode(error, nil, content_type) conn - |> put_resp_content_type(content_type) + |> put_resp_content_type(content_type, nil) |> send_resp(Error.code_to_status(error.code), body) |> halt() end diff --git a/test/twirp/plug_test.exs b/test/twirp/plug_test.exs index 737c6b5..d1ffb8c 100644 --- a/test/twirp/plug_test.exs +++ b/test/twirp/plug_test.exs @@ -73,10 +73,9 @@ defmodule Twirp.PlugTest do end def content_type(conn) do - conn.resp_headers - |> Enum.find_value(fn {h, v} -> if h == "content-type", do: v, else: false end) - |> String.split(";") # drop the charset if there is one - |> Enum.at(0) + Enum.find_value(conn.resp_headers, fn {h, v} -> + if h == "content-type", do: v, else: false + end) end def call(req, opts \\ @opts) do