Class: Async::HTTP::Protocol::HTTP1::Connection
- Inherits:
-
Protocol::HTTP1::Connection
- Object
- Protocol::HTTP1::Connection
- Async::HTTP::Protocol::HTTP1::Connection
- Defined in:
- lib/async/http/protocol/http1/connection.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #as_json ⇒ Object
- #concurrency ⇒ Object
- #http1? ⇒ Boolean
- #http2? ⇒ Boolean
-
#initialize(stream, version, **options) ⇒ Connection
constructor
A new instance of Connection.
- #peer ⇒ Object
- #reusable? ⇒ Boolean
- #to_json ⇒ Object
- #to_s ⇒ Object
-
#viable? ⇒ Boolean
Can we use this connection to make requests?.
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, **) super(stream, **) # 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
#count ⇒ Object (readonly)
Returns the value of attribute count.
50 51 52 |
# File 'lib/async/http/protocol/http1/connection.rb', line 50 def count @count end |
#version ⇒ Object (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_json ⇒ Object
28 29 30 |
# File 'lib/async/http/protocol/http1/connection.rb', line 28 def as_json(...) to_s end |
#concurrency ⇒ Object
52 53 54 |
# File 'lib/async/http/protocol/http1/connection.rb', line 52 def concurrency 1 end |
#http1? ⇒ Boolean
38 39 40 |
# File 'lib/async/http/protocol/http1/connection.rb', line 38 def http1? true end |
#http2? ⇒ Boolean
42 43 44 |
# File 'lib/async/http/protocol/http1/connection.rb', line 42 def http2? false end |
#peer ⇒ Object
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
61 62 63 |
# File 'lib/async/http/protocol/http1/connection.rb', line 61 def reusable? @persistent && @stream && !@stream.closed? end |
#to_json ⇒ Object
32 33 34 |
# File 'lib/async/http/protocol/http1/connection.rb', line 32 def to_json(...) as_json.to_json(...) end |
#to_s ⇒ Object
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?
57 58 59 |
# File 'lib/async/http/protocol/http1/connection.rb', line 57 def viable? self.idle? && @stream&.readable? end |