From 02af920a0f806117c7a8041bd5b50b28bcf7a996 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Sun, 24 Jan 2016 17:44:37 +0200 Subject: [PATCH] Make default content-type text/html --- spec/context_spec.cr | 11 +++++++++++ src/kemal/handler.cr | 2 ++ src/kemal/view.cr | 9 ++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/spec/context_spec.cr b/spec/context_spec.cr index 14e3712..c3a41af 100644 --- a/spec/context_spec.cr +++ b/spec/context_spec.cr @@ -1,6 +1,17 @@ require "./spec_helper" describe "Context" do + it "sets content type" do + kemal = Kemal::Handler.new + kemal.add_route "GET", "/" do |env| + "Hello" + end + request = HTTP::Request.new("GET", "/") + io_with_context = create_request_and_return_io(kemal, request) + client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false) + client_response.headers["Content-Type"].should eq("text/html") + end + it "sets content type" do kemal = Kemal::Handler.new kemal.add_route "GET", "/" do |env| diff --git a/src/kemal/handler.cr b/src/kemal/handler.cr index cdc0674..27a9637 100644 --- a/src/kemal/handler.cr +++ b/src/kemal/handler.cr @@ -12,6 +12,7 @@ class Kemal::Handler < HTTP::Handler end def call(context) + context.response.content_type = "text/html" response = process_request(context) response || call_next(context) end @@ -31,6 +32,7 @@ class Kemal::Handler < HTTP::Handler route = lookup.payload as Route if route.match?(context.request) begin + context.response.content_type = "text/html" body = route.handler.call(context).to_s context.response.print body return context diff --git a/src/kemal/view.cr b/src/kemal/view.cr index 2e72f7f..c1cb244 100644 --- a/src/kemal/view.cr +++ b/src/kemal/view.cr @@ -18,7 +18,8 @@ def render_403(context) HTML context.response.status_code = 403 - context.response.puts template + context.response.print template + context end # Template for 404 Not Found @@ -40,7 +41,8 @@ def render_404(context) HTML context.response.status_code = 404 - context.response.puts template + context.response.print template + context end # Template for 500 Internal Server Error @@ -62,5 +64,6 @@ def render_500(context, ex) HTML context.response.status_code = 500 - context.response.puts template + context.response.print template + context end