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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Split

#initialize, #to_s

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.

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


59
60
61
# File 'lib/protocol/http/header/connection.rb', line 59

def close?
  self.include?(CLOSE)
end

#keep_alive?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/protocol/http/header/connection.rb', line 54

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

#upgrade?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/protocol/http/header/connection.rb', line 64

def upgrade?
  self.include?(UPGRADE)
end