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
Overview
An HTTP/1 connection that wraps an IO stream with version and state tracking.
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
Initialize the connection with an IO stream and HTTP version.
- #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
Initialize the connection with an IO stream and HTTP version.
22 23 24 25 26 27 |
# File 'lib/async/http/protocol/http1/connection.rb', line 22 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.
61 62 63 |
# File 'lib/async/http/protocol/http1/connection.rb', line 61 def count @count end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
44 45 46 |
# File 'lib/async/http/protocol/http1/connection.rb', line 44 def version @version end |
Instance Method Details
#as_json ⇒ Object
35 36 37 |
# File 'lib/async/http/protocol/http1/connection.rb', line 35 def as_json(...) to_s end |
#concurrency ⇒ Object
64 65 66 |
# File 'lib/async/http/protocol/http1/connection.rb', line 64 def concurrency 1 end |
#http1? ⇒ Boolean
47 48 49 |
# File 'lib/async/http/protocol/http1/connection.rb', line 47 def http1? true end |
#http2? ⇒ Boolean
52 53 54 |
# File 'lib/async/http/protocol/http1/connection.rb', line 52 def http2? false end |
#peer ⇒ Object
57 58 59 |
# File 'lib/async/http/protocol/http1/connection.rb', line 57 def peer @peer ||= ::Protocol::HTTP::Peer.for(@stream.io) end |
#reusable? ⇒ Boolean
74 75 76 |
# File 'lib/async/http/protocol/http1/connection.rb', line 74 def reusable? @persistent && @stream && !@stream.closed? end |
#to_json ⇒ Object
40 41 42 |
# File 'lib/async/http/protocol/http1/connection.rb', line 40 def to_json(...) as_json.to_json(...) end |
#to_s ⇒ Object
30 31 32 |
# File 'lib/async/http/protocol/http1/connection.rb', line 30 def to_s "\#<#{self.class} negotiated #{@version}, #{@state}>" end |
#viable? ⇒ Boolean
Can we use this connection to make requests?
69 70 71 |
# File 'lib/async/http/protocol/http1/connection.rb', line 69 def viable? self.idle? && @stream&.readable? end |