Protocol::HTTPSourceProtocolHTTPBodyHead

class Head

Represents a body suitable for HEAD requests, in other words, a body that is empty and has a known length.

Definitions

def self.for(body, length = nil)

Create a head body for the given body, capturing its length and then closing it.

If a body is provided, the length is determined from the body, and the body is closed. If no body is provided, and the content length is provided, a head body is created with that length. This is useful for creating a head body when you only know the content length but not the actual body, which may happen in adapters for HTTP applications where the application may not provide a body for HEAD requests, but the content length is known.

Signature

parameter body Readable | Nil

the body to create a head for.

parameter length Integer | Nil

the content length of the body, if known.

returns Head | Nil

the head body, or nil if the body is nil.

Implementation

def self.for(body, length = nil)
	if body
		head = self.new(body.length)
		body.close
		return head
	elsif length
		return self.new(length)
	end
	
	return nil
end

def initialize(length)

Initialize the head body with the given length.

Signature

parameter length Integer

the length of the body.

Implementation

def initialize(length)
	@length = length
end

def empty?

Signature

returns Boolean

the body is empty.

Implementation

def empty?
	true
end

def ready?

Signature

returns Boolean

the body is ready.

Implementation

def ready?
	true
end

def length

Signature

returns Integer

the length of the body, if known.

Implementation

def length
	@length
end