Async::HTTPSourceAsyncHTTPBodyHijack

class Hijack

A body which is designed for hijacked server responses - a response which uses a block to read and write the request and response bodies respectively.

Definitions

def stream?

We prefer streaming directly as it's the lowest overhead.

Implementation

def stream?
	true
end

def empty?

Has the producer called #finish and has the reader consumed the nil token?

Implementation

def empty?
	@output&.empty?
end

def read

Read the next available chunk.

Implementation

def read
	unless @output
		@output = Writable.new
		@stream = ::Protocol::HTTP::Body::Stream.new(@input, @output)
		
		@task = Task.current.async do |task|
			task.annotate "Streaming hijacked body."
			
			@block.call(@stream)
		end
	end
	
	return @output.read
end