Class: Protocol::HTTP::Header::Connection

Inherits:
Split
  • Object
show all
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

Split::COMMA

Instance Method Summary collapse

Methods inherited from Split

#to_s

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

Returns:

  • (Boolean)


45
46
47
# File 'lib/protocol/http/header/connection.rb', line 45

def close?
	self.include?(CLOSE)
end

#keep_alive? ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/protocol/http/header/connection.rb', line 40

def keep_alive?
	self.include?(KEEP_ALIVE) && !close?
end

#upgrade? ⇒ Boolean

Returns:

  • (Boolean)


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

def upgrade?
	self.include?(UPGRADE)
end