From 93d61a938f898040c384a5bb9d2fb4fab003f8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lennart=20Fride=CC=81n?= Date: Sat, 6 Jun 2015 19:11:58 +0200 Subject: [PATCH] Use put_resp_content_type which sets the charset to UTF-8. --- lib/plug_require_header.ex | 4 ++-- test/plug_require_header_test.exs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/plug_require_header.ex b/lib/plug_require_header.ex index dabb924..4647545 100644 --- a/lib/plug_require_header.ex +++ b/lib/plug_require_header.ex @@ -97,14 +97,14 @@ defmodule PlugRequireHeader do conn else conn - |> put_resp_header("content-type", content_type_for(format)) + |> put_resp_content_type(content_type_for format) |> send_resp(status, format_message(message, format)) |> halt end end end - defp content_type_for(:text), do: "text/plain; charset=utf-8" + defp content_type_for(:text), do: "text/plain" defp content_type_for(:json), do: "application/json" defp format_message(message, :text), do: message diff --git a/test/plug_require_header_test.exs b/test/plug_require_header_test.exs index 4eaf769..dfffc03 100644 --- a/test/plug_require_header_test.exs +++ b/test/plug_require_header_test.exs @@ -99,7 +99,7 @@ defmodule PlugRequireHeaderTest do assert response.status == 418 assert response.resp_body == Poison.encode! %{error: "I'm a teapot!"} - assert content_type(response) == "application/json" + assert content_type(response) == "application/json; charset=utf-8" end defp content_type(response) do