Delete Content-Length. Conten-Type and body on status 204
Should work, but somehow it doesn't...
This commit is contained in:
parent
fea8ac2bbd
commit
bffdca6cb1
|
@ -30,12 +30,18 @@ module Zero
|
|||
#
|
||||
# @return [Array]
|
||||
#
|
||||
def to_a()
|
||||
def to_a
|
||||
# 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'
|
||||
# Set content type, if not already set
|
||||
content_type 'text/html' unless header.has_key? 'Content-Type'
|
||||
if status == 204
|
||||
header.delete('Content-Length')
|
||||
header.delete('Content-Type')
|
||||
body = []
|
||||
else
|
||||
# Set content length, if not already set
|
||||
content_length unless header.has_key? 'Content-Length'
|
||||
# Set content type, if not already set
|
||||
content_type 'text/html' unless header.has_key? 'Content-Type'
|
||||
end
|
||||
|
||||
[status, header, body]
|
||||
end
|
||||
|
|
|
@ -45,6 +45,17 @@ describe Zero::Response do
|
|||
|
||||
value[1]['Content-Type'].should eq('text/html') # Headers
|
||||
end
|
||||
|
||||
it "removes Content-Type, Content-Length and body on status code 204" do
|
||||
subject.body.push '"foobar"'
|
||||
subject.content_type 'application/json'
|
||||
subject.header['Content-Length'] = 8
|
||||
|
||||
subject.status = 204
|
||||
value = subject.to_a
|
||||
|
||||
value[1].should eq({}) # Headers
|
||||
end
|
||||
end
|
||||
|
||||
describe '#status' do
|
||||
|
|
Loading…
Reference in New Issue