0
0
zero/lib/zero/response.rb
Stormwind 963adb8ddc content_length sets the Content-Length to 0
The method content_length creates a header named Content-Length and sets
its value to 0.
2012-11-23 17:43:39 +01:00

50 lines
1.0 KiB
Ruby

module Zero
# This is the representation of a response
#
class Response
attr_reader :status
attr_accessor :header, :body
# Constructor
# Sets default status code to 200.
#
def initialize
@status = 200
@header = {}
@body = []
end
# Sets the status.
# Also converts every input directly to an integer
#
# @param [Integer] status
#
def status=(status)
@status = status.to_i
end
# Returns the data of the response as an array:
# [status, header, body]
# to be usable by any webserver
#
# @return [Array]
#
def to_a()
# TODO Remove content length and body, on certain status codes
# TODO Set content length, if not already set
# TODO Set content type, if not already set
[@status, @header, @body]
end
# Sets the content length header to the current length of the body
# Also creates one, if it does not exists
#
def content_length
header['Content-Length'] = 0
end
end
end