Class: Async::HTTP::Protocol::HTTP1::Response

Inherits:
Response
  • Object
show all
Defined in:
lib/async/http/protocol/http1/response.rb

Overview

An HTTP/1 response received from a server.

Constant Summary collapse

UPGRADE =
"upgrade"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Response

#inspect, #peer, #remote_address

Constructor Details

#initialize(connection, version, status, reason, headers, body) ⇒ Response

Returns a new instance of Response.



37
38
39
40
41
42
43
44
45
# File 'lib/async/http/protocol/http1/response.rb', line 37

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

Instance Attribute Details

#reasonObject (readonly)

Returns the value of attribute reason.



34
35
36
# File 'lib/async/http/protocol/http1/response.rb', line 34

def reason
  @reason
end

#The HTTP response line reason.(HTTPresponselinereason.) ⇒ Object (readonly)



34
# File 'lib/async/http/protocol/http1/response.rb', line 34

attr :reason

Class Method Details

.read(connection, request) ⇒ Object

Read the response from the connection, handling interim responses.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/async/http/protocol/http1/response.rb', line 19

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

Instance Method Details

#connectionObject



58
59
60
# File 'lib/async/http/protocol/http1/response.rb', line 58

def connection
	@connection
end

#hijack!Object

Hijack the underlying connection for bidirectional communication.



68
69
70
# File 'lib/async/http/protocol/http1/response.rb', line 68

def hijack!
	@connection.hijack!
end

#hijack?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/async/http/protocol/http1/response.rb', line 63

def hijack?
	@body.nil?
end

#pool=(pool) ⇒ Object

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



49
50
51
52
53
54
55
# File 'lib/async/http/protocol/http1/response.rb', line 49

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