Module: Async::HTTP::Body::Reader

Included in:
Request, Response
Defined in:
lib/async/http/body/reader.rb

Instance Method Summary collapse

Instance Method Details

#body?Boolean

Whether there is a body?

Returns:

  • (Boolean)


58
59
60
# File 'lib/async/http/body/reader.rb', line 58

def body?
	@body and !@body.empty?
end

#closeObject

Close the connection as quickly as possible. Discards body.



53
54
55
# File 'lib/async/http/body/reader.rb', line 53

def close
	self.stop
end

#each(&block) ⇒ Object

Read chunks from the body.



26
27
28
# File 'lib/async/http/body/reader.rb', line 26

def each(&block)
	self.body.each(&block)
end

#finishObject

Gracefully finish reading the body. This will buffer the remainder of the body.



46
47
48
49
50
# File 'lib/async/http/body/reader.rb', line 46

def finish
	if self.body
		self.body = self.body.close
	end
end

#readObject

Reads the entire request/response body.



31
32
33
34
35
# File 'lib/async/http/body/reader.rb', line 31

def read
	if self.body
		self.body.join
	end
end

#stop(error = EOFError) ⇒ Object

Immediately stop reading the body. May close the underlying connection. Discards body.



38
39
40
41
42
43
# File 'lib/async/http/body/reader.rb', line 38

def stop(error = EOFError)
	if self.body
		self.body.stop(error)
		self.body = nil
	end
end