From fea8ac2bbd04fd4abea929fef1b7e8ac305b4ca1 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Fri, 23 Nov 2012 20:05:58 +0100 Subject: Sets the Content-Type in to_a unless it is already set before The default value is 'text/html'. --- lib/zero/response.rb | 3 ++- spec/unit/response/response_spec.rb | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/zero/response.rb b/lib/zero/response.rb index 0d23194..fefa320 100644 --- a/lib/zero/response.rb +++ b/lib/zero/response.rb @@ -34,7 +34,8 @@ module Zero # TODO Remove content length and body, on certain status codes # Set content length, if not already set content_length unless header.has_key? 'Content-Length' - # TODO Set content type, if not already set + # Set content type, if not already set + content_type 'text/html' unless header.has_key? 'Content-Type' [status, header, body] end diff --git a/spec/unit/response/response_spec.rb b/spec/unit/response/response_spec.rb index 58b8d07..18612ce 100644 --- a/spec/unit/response/response_spec.rb +++ b/spec/unit/response/response_spec.rb @@ -14,7 +14,7 @@ describe Zero::Response do value.should be_an_instance_of(Array) value[0].should eq(200) # Status code - value[1].should eq({"Content-Length" => 0}) # Headers + value[1].should be_an_instance_of(Hash) # Headers value[2].should eq([]) # Body end @@ -22,7 +22,7 @@ describe Zero::Response do subject.body = ['foobar'] value = subject.to_a - value[1].should eq({'Content-Length' => 6}) # Headers + value[1]['Content-Length'].should eq(6) # Headers end it "does not fix the Content-Length, if it's already set" do @@ -30,7 +30,20 @@ describe Zero::Response do subject.header = {'Content-Length' => 3} value = subject.to_a - value[1].should eq({'Content-Length' => 3}) # Headers + value[1]['Content-Length'].should eq(3) # Headers + end + + it "returns the Content-Type in the header" do + subject.header = {'Content-Type' => 'application/json'} + value = subject.to_a + + value[1]['Content-Type'].should eq('application/json') # Headers + end + + it "returns as default 'text/html' as Content-Type" do + value = subject.to_a + + value[1]['Content-Type'].should eq('text/html') # Headers end end -- cgit v1.2.3-70-g09d2