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-alive` directive indicates that the connection should remain open for future requests or responses, avoiding the overhead of opening a new connection.
"keep-alive"- CLOSE =
The ‘close` directive indicates that the connection should be closed after the current request and response are complete.
"close"- UPGRADE =
The ‘upgrade` directive indicates that the connection should be upgraded to a different protocol, as specified in the `Upgrade` header.
"upgrade"
Constants inherited from Split
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
-
.parse(value) ⇒ Object
Parses a raw header value.
-
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers.
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Adds a directive to the ‘connection` header.
- #close? ⇒ Boolean
- #keep_alive? ⇒ Boolean
- #upgrade? ⇒ Boolean
Methods inherited from Split
Constructor Details
This class inherits a constructor from Protocol::HTTP::Header::Split
Class Method Details
.coerce(value) ⇒ Object
Coerces a value into a parsed header object.
37 38 39 40 41 42 43 44 |
# File 'lib/protocol/http/header/connection.rb', line 37 def self.coerce(value) case value when Array self.new(value.map(&:downcase)) else self.parse(value.to_s) end end |
.parse(value) ⇒ Object
Parses a raw header value.
29 30 31 |
# File 'lib/protocol/http/header/connection.rb', line 29 def self.parse(value) self.new(value.downcase.split(COMMA)) end |
.trailer? ⇒ Boolean
Whether this header is acceptable in HTTP trailers. Connection headers control the current connection and must not appear in trailers.
71 72 73 |
# File 'lib/protocol/http/header/connection.rb', line 71 def self.trailer? false end |
Instance Method Details
#<<(value) ⇒ Object
Adds a directive to the ‘connection` header. The value will be normalized to lowercase before being added.
49 50 51 |
# File 'lib/protocol/http/header/connection.rb', line 49 def << value super(value.downcase) end |
#close? ⇒ Boolean
59 60 61 |
# File 'lib/protocol/http/header/connection.rb', line 59 def close? self.include?(CLOSE) end |
#keep_alive? ⇒ Boolean
54 55 56 |
# File 'lib/protocol/http/header/connection.rb', line 54 def keep_alive? self.include?(KEEP_ALIVE) && !close? end |
#upgrade? ⇒ Boolean
64 65 66 |
# File 'lib/protocol/http/header/connection.rb', line 64 def upgrade? self.include?(UPGRADE) end |