0
0
Fork 0

Sets Content-Length to body string length

It joins the body array to a string and sets the Content-Length header
to its length.
This commit is contained in:
Stormwind 2012-11-23 17:59:33 +01:00
parent 22cf93d002
commit b4e56c6868
2 changed files with 8 additions and 1 deletions

View File

@ -42,7 +42,7 @@ module Zero
# Also creates one, if it does not exists
#
def content_length
header['Content-Length'] = 0
header['Content-Length'] = body.join.length
end
end

View File

@ -53,6 +53,13 @@ describe Zero::Response do
subject.header['Content-Length'].should eq(0)
end
it "sets the content_length to the size of the message body" do
subject.body = ['foo', 'bar']
subject.content_length
subject.header['Content-Length'].should eq(6)
end
end
end