Module: Hitch::MCP::Internal::HeaderField

Defined in:
app/models/hitch/mcp/internal/header_field.rb

Overview

Field-value hygiene shared by the endpoint and the verified request: reject control bytes and comma-combined values, trim optional whitespace (RFC 9110 ยง5.5-5.6).

Constant Summary collapse

CONTROLS =
/[\x00-\x08\x0A-\x1F\x7F]/
OWS =
/\A[\x20\x09]*(.*?)[\x20\x09]*\z/m

Class Method Summary collapse

Class Method Details

.single(value) ⇒ Object

The one exact value of a header that must not repeat: nil for missing, invalid, comma-combined, or empty-after-trim values.



17
18
19
20
21
22
23
# File 'app/models/hitch/mcp/internal/header_field.rb', line 17

def single(value)
  return unless value.is_a?(String) && value.valid_encoding?
  return if value.include?(",") || CONTROLS.match?(value)

  candidate = trim_ows(value)
  candidate unless candidate.nil? || candidate.empty?
end

.trim_ows(value) ⇒ Object



25
26
27
# File 'app/models/hitch/mcp/internal/header_field.rb', line 25

def trim_ows(value)
  value[OWS, 1]
end