The default number of bytes of the response body to send to the mongrel2 server at a time.
The body of the response as an IO (or IOish) object
The number of bytes to write to Mongrel in a single “chunk”
The response’s connection ID; this corresponds to the identifier of the connection the response will be routed to by the mongrel2 server
The request that this response is for, if there is one
The response’s UUID; this corresponds to the mongrel2 server the response will be routed to by the Connection.
Create a response to the specified
request and return it.
# File lib/mongrel2/response.rb, line 24 def self::from_request( request ) self.log.debug "Creating a %p to request %p" % [ self, request ] response = new( request.sender_id, request.conn_id ) response.request = request return response end
Create a new Response object for the specified
# File lib/mongrel2/response.rb, line 34 def initialize( sender_id, conn_id, body='' ) body = StringIO.new( body, 'a+' ) unless body.respond_to?( :read ) @sender_id = sender_id @conn_id = conn_id @body = body @request = nil @chunksize = DEFAULT_CHUNKSIZE end
Append the given
object to the response body. Returns the
response for chaining.
# File lib/mongrel2/response.rb, line 77 def <<( object ) self.body << object return self end
Set the response’s entity body to
newbody is a String-ish object (i.e., it responds to to_str),
it will be wrapped in a StringIO in ‘a+’ mode).
# File lib/mongrel2/response.rb, line 69 def body=( newbody ) newbody = StringIO.new( newbody, 'a+' ) if newbody.respond_to?( :to_str ) @body = newbody end
Yield chunks of the response to the caller’s block. By default, just yields the result of calling to_s on the response.
# File lib/mongrel2/response.rb, line 101 def each_chunk if block_given? yield( self.to_s ) else return [ self.to_s ].to_enum end end
Returns a string containing a human-readable representation of the Response, suitable for debugging.
# File lib/mongrel2/response.rb, line 112 def inspect return "#<%p:0x%016x %s (%s/%d)>" % [ self.class, self.object_id * 2, self.inspect_details, self.sender_id, self.conn_id ] end
Write the given
objects to the response body, calling to_s on each one.
# File lib/mongrel2/response.rb, line 84 def puts( *objects ) self.body.puts( *objects ) end
Stringify the response, which just returns its body.
# File lib/mongrel2/response.rb, line 90 def to_s pos = self.body.pos self.body.pos = 0 return self.body.read ensure self.body.pos = pos end
Return the details to include in the contents of the inspected object. This method allows other request types to provide their own details while keeping the form somewhat consistent.
# File lib/mongrel2/response.rb, line 130 def inspect_details return "%p body" % [ self.body.class ] end