Protocol::HTTPSourceProtocolHTTPBodyWrapper

class Wrapper

Wrapping body instance. Typically you'd override #read.

Definitions

def self.wrap(message)

Wrap the body of the given message in a new instance of this class.

Signature

parameter message Request | Response

the message to wrap.

returns Wrapper | Nil

the wrapped body or nil`` if the body was nil`.

Implementation

def self.wrap(message)
	if body = message.body
		message.body = self.new(body)
	end
end

def initialize(body)

Initialize the wrapper with the given body.

Signature

parameter body Readable

The body to wrap.

Implementation

def initialize(body)
	@body = body
end

attr :body

Signature

attribute Readable

The wrapped body.

def close(error = nil)

Close the body.

Signature

parameter error Exception | Nil

The error that caused this stream to be closed, if any.

Implementation

def close(error = nil)
	@body.close(error)
	
	# It's a no-op:
	# super
end

def empty?

Forwards to the wrapped body.

Implementation

def empty?
	@body.empty?
end

def ready?

Forwards to the wrapped body.

Implementation

def ready?
	@body.ready?
end

def buffered

Forwards to the wrapped body.

Implementation

def buffered
	@body.buffered
end

def rewind

Forwards to the wrapped body.

Implementation

def rewind
	@body.rewind
end

def rewindable?

Forwards to the wrapped body.

Implementation

def rewindable?
	@body.rewindable?
end

def length

Forwards to the wrapped body.

Implementation

def length
	@body.length
end

def read

Forwards to the wrapped body.

Implementation

def read
	@body.read
end

def discard

Forwards to the wrapped body.

Implementation

def discard
	@body.discard
end

def as_json(...)

Convert the body to a hash suitable for serialization.

Signature

returns Hash

The body as a hash.

Implementation

def as_json(...)
	{
		class: self.class.name,
		body: @body&.as_json
	}
end

def to_json(...)

Convert the body to JSON.

Signature

returns String

The body as JSON.

Implementation

def to_json(...)
	as_json.to_json(...)
end

def inspect

Inspect the wrapped body. The wrapper, by default, is transparent.

Signature

returns String

a string representation of the wrapped body.

Implementation

def inspect
	@body.inspect
end