From 92d72737596359d98cc7aaedebc2fbbb487707b2 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Sat, 14 May 2016 11:07:19 +0300 Subject: [PATCH] Inherit response.content type from filter if it's given. Fixes #146. --- spec/route_handler_spec.cr | 9 +++++++++ src/kemal/route_handler.cr | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/route_handler_spec.cr b/spec/route_handler_spec.cr index a3a108f..6da6f31 100644 --- a/spec/route_handler_spec.cr +++ b/spec/route_handler_spec.cr @@ -155,4 +155,13 @@ describe "Kemal::RouteHandler" do client_response.status_code.should eq(302) client_response.headers.has_key?("Location").should eq(true) end + + it "sets default Content-Type to context html" do + get "/" do |env| + "Hello World from GET" + end + request = HTTP::Request.new("GET", "/") + client_response = call_request_on_app(request) + client_response.content_type.should eq("text/html") + end end diff --git a/src/kemal/route_handler.cr b/src/kemal/route_handler.cr index 1f3ad65..cd45c4e 100644 --- a/src/kemal/route_handler.cr +++ b/src/kemal/route_handler.cr @@ -13,7 +13,7 @@ class Kemal::RouteHandler < HTTP::Handler end def call(context) - context.response.content_type = "text/html" + context.response.content_type = "text/html" unless context.response.headers.has_key?("Content-Type") process_request(context) end