summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/zero/response.rb20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/zero/response.rb b/lib/zero/response.rb
index 15fb8c7..264c9ae 100644
--- a/lib/zero/response.rb
+++ b/lib/zero/response.rb
@@ -4,7 +4,8 @@ module Zero
#
class Response
attr_reader :status
- attr_accessor :header, :body
+ attr_reader :body
+ attr_accessor :header
# Constructor
# Sets default status code to 200.
@@ -24,6 +25,23 @@ module Zero
@status = status.to_i
end
+ # set the body to a new value
+ #
+ # Use this function to set the body to a new value. It can either be an
+ # Object responding to `#each` per rack convention or a kind of string.
+ #
+ # @param content [#each, String] the content of the body
+ def body=(content)
+ content = [content] if content.kind_of?(String)
+
+ unless content.respond_to?(:each) then
+ raise ArgumentError.new(
+ "invalid body! Should be kind of String or respond to #each!")
+ end
+
+ @body = content
+ end
+
# Returns the data of the response as an array:
# [status, header, body]
# to be usable by any webserver.