From a2e6c299cd15b8335441e3b5ba07fe95256f3a2d Mon Sep 17 00:00:00 2001 From: Stormwind Date: Fri, 23 Nov 2012 18:06:53 +0100 Subject: [PATCH] Sets Content-Length to body string bytesize Sets the Conten-Length to the bytesize of the joined body to cover UTF-8 --- lib/zero/response.rb | 2 +- spec/unit/response/response_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/zero/response.rb b/lib/zero/response.rb index 2886a0d..b8aeff0 100644 --- a/lib/zero/response.rb +++ b/lib/zero/response.rb @@ -42,7 +42,7 @@ module Zero # Also creates one, if it does not exists # def content_length - header['Content-Length'] = body.join.length + header['Content-Length'] = body.join.bytesize end end diff --git a/spec/unit/response/response_spec.rb b/spec/unit/response/response_spec.rb index 21d6e31..e58b0d0 100644 --- a/spec/unit/response/response_spec.rb +++ b/spec/unit/response/response_spec.rb @@ -1,3 +1,4 @@ +# encoding: UTF-8 require 'spec_helper' describe Zero::Response do @@ -60,6 +61,13 @@ describe Zero::Response do subject.header['Content-Length'].should eq(6) end + + it "sets the content_length to the bytesize of the message body" do + subject.body = ['föö', 'bär'] + subject.content_length + + subject.header['Content-Length'].should eq(9) + end end end \ No newline at end of file