Class: Protocol::HTTP::Header::Connection
- Defined in:
- lib/protocol/http/header/connection.rb
Overview
Represents the connection HTTP header, which controls options for the current connection.
The connection header is used to specify control options such as whether the connection should be kept alive, closed, or upgraded to a different protocol.
Constant Summary collapse
- KEEP_ALIVE =
The
keep-alivedirective indicates that the connection should remain open for future requests or responses, avoiding the overhead of opening a new connection. "keep-alive"- CLOSE =
The
closedirective indicates that the connection should be closed after the current request and response are complete. "close"- UPGRADE =
The
upgradedirective indicates that the connection should be upgraded to a different protocol, as specified in theUpgradeheader. "upgrade"
Constants inherited from Split
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Adds a directive to the
connectionheader. - #close? ⇒ Boolean
-
#initialize(value = nil) ⇒ Connection
constructor
Initializes the connection header with the given value.
- #keep_alive? ⇒ Boolean
- #upgrade? ⇒ Boolean
Methods inherited from Split
Constructor Details
#initialize(value = nil) ⇒ Connection
Initializes the connection header with the given value. The value is expected to be a comma-separated string of directives.
28 29 30 |
# File 'lib/protocol/http/header/connection.rb', line 28 def initialize(value = nil) super(value&.downcase) end |
Instance Method Details
#<<(value) ⇒ Object
Adds a directive to the connection header. The value will be normalized to lowercase before being added.
35 36 37 |
# File 'lib/protocol/http/header/connection.rb', line 35 def << value super(value.downcase) end |
#close? ⇒ Boolean
45 46 47 |
# File 'lib/protocol/http/header/connection.rb', line 45 def close? self.include?(CLOSE) end |
#keep_alive? ⇒ Boolean
40 41 42 |
# File 'lib/protocol/http/header/connection.rb', line 40 def keep_alive? self.include?(KEEP_ALIVE) && !close? end |
#upgrade? ⇒ Boolean
50 51 52 |
# File 'lib/protocol/http/header/connection.rb', line 50 def upgrade? self.include?(UPGRADE) end |