Class: Async::HTTP::Protocol::HTTP1::Connection

Inherits:
Protocol::HTTP1::Connection
  • Object
show all
Defined in:
lib/async/http/protocol/http1/connection.rb

Direct Known Subclasses

Client, Server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, version, **options) ⇒ Connection

Returns a new instance of Connection.



17
18
19
20
21
22
# File 'lib/async/http/protocol/http1/connection.rb', line 17

def initialize(stream, version, **options)
	super(stream, **options)
	
	# On the client side, we need to send the HTTP version with the initial request. On the server side, there are some scenarios (bad request) where we don't know the request version. In those cases, we use this value, which is either hard coded based on the protocol being used, OR could be negotiated during the connection setup (e.g. ALPN).
	@version = version
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



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

def count
  @count
end

#versionObject (readonly)

Returns the value of attribute version.



36
37
38
# File 'lib/async/http/protocol/http1/connection.rb', line 36

def version
  @version
end

Instance Method Details

#as_jsonObject



28
29
30
# File 'lib/async/http/protocol/http1/connection.rb', line 28

def as_json(...)
	to_s
end

#concurrencyObject



52
53
54
# File 'lib/async/http/protocol/http1/connection.rb', line 52

def concurrency
	1
end

#http1?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/async/http/protocol/http1/connection.rb', line 38

def http1?
	true
end

#http2?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/async/http/protocol/http1/connection.rb', line 42

def http2?
	false
end

#peerObject



46
47
48
# File 'lib/async/http/protocol/http1/connection.rb', line 46

def peer
	@peer ||= ::Protocol::HTTP::Peer.for(@stream.io)
end

#reusable?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/async/http/protocol/http1/connection.rb', line 61

def reusable?
	@persistent && @stream && !@stream.closed?
end

#to_jsonObject



32
33
34
# File 'lib/async/http/protocol/http1/connection.rb', line 32

def to_json(...)
	as_json.to_json(...)
end

#to_sObject



24
25
26
# File 'lib/async/http/protocol/http1/connection.rb', line 24

def to_s
	"\#<#{self.class} negotiated #{@version}, #{@state}>"
end

#viable?Boolean

Can we use this connection to make requests?

Returns:

  • (Boolean)


57
58
59
# File 'lib/async/http/protocol/http1/connection.rb', line 57

def viable?
	self.idle? && @stream&.readable?
end