Skip to content

Commit 95b8266

Browse files
authored
Merge pull request #35 from zverok/document-response-body
Document HTTPResponse#body callable option
2 parents d8086e6 + d51836d commit 95b8266

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/webrick/httpresponse.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,21 @@ class InvalidHeader < StandardError
5151
attr_accessor :reason_phrase
5252

5353
##
54-
# Body may be a String or IO-like object that responds to #read and
55-
# #readpartial.
54+
# Body may be:
55+
# * a String;
56+
# * an IO-like object that responds to +#read+ and +#readpartial+;
57+
# * a Proc-like object that responds to +#call+.
58+
#
59+
# In the latter case, either #chunked= should be set to +true+,
60+
# or <code>header['content-length']</code> explicitly provided.
61+
# Example:
62+
#
63+
# server.mount_proc '/' do |req, res|
64+
# res.chunked = true
65+
# # or
66+
# # res.header['content-length'] = 10
67+
# res.body = proc { |out| out.write(Time.now.to_s) }
68+
# end
5669

5770
attr_accessor :body
5871

0 commit comments

Comments
 (0)