Async::HTTPSourceAsyncHTTPProtocolHTTP1Response

class Response

An HTTP/1 response received from a server.

Definitions

def self.read(connection, request)

Read the response from the connection, handling interim responses.

Signature

parameter connection Connection

The HTTP/1 connection to read from.

parameter request Request

The original request.

returns Response | Nil

The final response.

Implementation

def self.read(connection, request)
	while parts = connection.read_response(request.method)
		response = self.new(connection, *parts)
		
		if response.final?
			return response
		else
			request.send_interim_response(response.status, response.headers)
		end
	end
end

attr :reason

Signature

attribute String

The HTTP response line reason.

def initialize(connection, version, status, reason, headers, body)

Signature

parameter reason String

HTTP response line reason phrase.

Implementation

def initialize(connection, version, status, reason, headers, body)
	@connection = connection
	@reason = reason
	
	# Technically, there should never be more than one value for the upgrade header, but we'll just take the first one to avoid complexity.
	protocol = headers.delete(UPGRADE)&.first
	
	super(version, status, headers, body, protocol)
end

def pool=(pool)

Assign the connection pool, releasing the connection if it is already idle or closed.

Signature

parameter pool Async::Pool::Controller

The connection pool.

Implementation

def pool=(pool)
	if @connection.idle? or @connection.closed?
		pool.release(@connection)
	else
		@connection.pool = pool
	end
end

def connection

Signature

returns Connection

The underlying HTTP/1 connection.

Implementation

def connection
	@connection
end

def hijack?

Signature

returns Boolean

Whether connection hijacking is available (when the body is nil).

Implementation

def hijack?
	@body.nil?
end

def hijack!

Hijack the underlying connection for bidirectional communication.

Implementation

def hijack!
	@connection.hijack!
end