From ffdaecace4cc3f0d168672907155c1a8967f11d4 Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Fri, 30 Oct 2015 17:06:25 +0200 Subject: [PATCH] Added headers to context --- spec/context_spec.cr | 13 +++++++++++++ src/kemal/context.cr | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/spec/context_spec.cr b/spec/context_spec.cr index 1712756..3a0113c 100644 --- a/spec/context_spec.cr +++ b/spec/context_spec.cr @@ -20,4 +20,17 @@ describe "Context" do response = kemal.call(request) response.headers["Content-Type"].should eq("application/json") end + + it "parses headers" do + kemal = Kemal::Handler.new + kemal.add_route "GET", "/" do |env| + name = env.headers["name"] + "Hello #{name}" + end + headers = HTTP::Headers.new + headers["Name"] = "kemal" + request = HTTP::Request.new("GET", "/", headers) + response = kemal.call(request) + response.body.should eq "Hello kemal" + end end diff --git a/src/kemal/context.cr b/src/kemal/context.cr index 5378b06..887320d 100644 --- a/src/kemal/context.cr +++ b/src/kemal/context.cr @@ -9,6 +9,10 @@ class Kemal::Context @content_type = "text/html" end + def headers + request.headers + end + def set_content_type(content_type) @content_type = content_type end