Class: Protocol::HTTP::Body::Cacheable

Inherits:
Rewindable show all
Defined in:
lib/protocol/http/body/cacheable.rb

Instance Attribute Summary

Attributes inherited from Wrapper

#body

Class Method Summary collapse

Methods inherited from Rewindable

#buffered, #initialize, #inspect, #read, #rewind

Methods inherited from Wrapper

#close, #empty?, #finish, #initialize, #inspect, #length, #read

Methods inherited from Readable

#close, #each, #empty?, #finish, #join, #length, #read

Constructor Details

This class inherits a constructor from Protocol::HTTP::Body::Rewindable

Class Method Details

.wrap(message, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/protocol/http/body/cacheable.rb', line 30

def self.wrap(message, &block)
	if body = message.body
		# Create a rewindable body wrapping the message body:
		rewindable = Rewindable.new(body)
		
		# Set the message body to the rewindable body:
		message.body = rewindable
		
		# Wrap the message with the callback:
		Streamable.wrap(message) do |error|
			unless error
				yield message, rewindable.buffered
			end
		end
	else
		yield message, nil
	end
end