Class: HTTP::Headers::Normalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/http/headers/normalizer.rb

Defined Under Namespace

Classes: Cache

Constant Summary collapse

CANONICAL_NAME_RE =

Matches HTTP header names when in "Canonical-Http-Format"

/\A[A-Z][a-z]*(?:-[A-Z][a-z]*)*\z/
COMPLIANT_NAME_RE =

Matches valid header field name according to RFC.

/\A[A-Za-z0-9!#$%&'*+\-.^_`|~]+\z/
NAME_PARTS_SEPARATOR_RE =
/[\-_]/

Instance Method Summary collapse

Constructor Details

#initializeNormalizer

Returns a new instance of Normalizer.



38
39
40
# File 'lib/http/headers/normalizer.rb', line 38

def initialize
  @cache = Cache.new
end

Instance Method Details

#call(name) ⇒ Object

Transforms name to canonical HTTP header capitalization



43
44
45
46
47
48
# File 'lib/http/headers/normalizer.rb', line 43

def call(name)
  name  = -name.to_s
  value = (@cache[name] ||= -normalize_header(name))

  value.dup
end