From 78121c6eea9cc6d2a669c93f0b89557b5c59babc Mon Sep 17 00:00:00 2001 From: Stormwind Date: Fri, 23 Nov 2012 19:39:56 +0100 Subject: [PATCH] Sets the Content-Length in to_a unless it is already set before --- lib/zero/response.rb | 4 ++-- spec/unit/response/response_spec.rb | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/zero/response.rb b/lib/zero/response.rb index 2660924..eec4559 100644 --- a/lib/zero/response.rb +++ b/lib/zero/response.rb @@ -32,8 +32,8 @@ module Zero # def to_a() # TODO Remove content length and body, on certain status codes - # TODO Set content length, if not already set - content_length + # Set content length, if not already set + content_length unless header.has_key? 'Content-Length' # TODO Set content type, if not already set [status, header, body] diff --git a/spec/unit/response/response_spec.rb b/spec/unit/response/response_spec.rb index 9f6a3a0..b6428fc 100644 --- a/spec/unit/response/response_spec.rb +++ b/spec/unit/response/response_spec.rb @@ -19,12 +19,19 @@ describe Zero::Response do end it "returns the content length in the header" do - subject.body = ['foobar'] - + subject.body = ['foobar'] value = subject.to_a value[1].should eq({'Content-Length' => 6}) # Headers end + + it "does not fix the Content-Length, if it's already set" do + subject.body = ['foobar'] + subject.header = {'Content-Length' => 3} + value = subject.to_a + + value[1].should eq({'Content-Length' => 3}) # Headers + end end describe '#status' do