Class: HTTP::Headers::Normalizer

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

Overview

Normalizes HTTP header names to canonical form

Constant Summary collapse

COMPLIANT_NAME_RE =

Matches valid header field name according to RFC.

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

Pattern matching header name part separators (hyphens and underscores)

/[-_]/
CACHE_KEY =

Thread-local cache key for normalized header names

:http_headers_normalizer_cache

Instance Method Summary collapse

Instance Method Details

#call(name) ⇒ String

Normalizes a header name to canonical form

Examples:

normalizer.call("content-type")

Returns:

  • (String)


24
25
26
27
28
29
30
# File 'lib/http/headers/normalizer.rb', line 24

def call(name)
  name  = name.to_s
  cache = (Thread.current[CACHE_KEY] ||= {})
  value = (cache[name] ||= normalize_header(name))

  value.dup
end