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

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

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, #remote_address=

Constructor Details

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

Returns a new instance of Response.



32
33
34
35
36
37
38
39
40
# File 'lib/async/http/protocol/http1/response.rb', line 32

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.



29
30
31
# File 'lib/async/http/protocol/http1/response.rb', line 29

def reason
  @reason
end

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



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

attr :reason

Class Method Details

.read(connection, request) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/async/http/protocol/http1/response.rb', line 14

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



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

def connection
	@connection
end

#hijack!Object



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

def hijack!
	@connection.hijack!
end

#hijack?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/async/http/protocol/http1/response.rb', line 54

def hijack?
	@body.nil?
end

#pool=(pool) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/async/http/protocol/http1/response.rb', line 42

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