Class: Tina4::CaseInsensitiveHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/tina4/request.rb

Overview

Hash subclass for HTTP headers — string keys are case-insensitive.

HTTP header field-names are case-insensitive per RFC 7230 §3.2. With this class, request.headers, .headers, and .headers all return the same value. Keys are stored lowercase internally.

Cross-framework parity: same behaviour ships in tina4-python (CaseInsensitiveDict), tina4-php (Tina4Request), tina4-nodejs (Tina4Request). tina4-book#141 PY-10-03 — chapter 10 examples documented headers for years; this makes them work.

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



71
72
73
# File 'lib/tina4/request.rb', line 71

def [](key)
  super(normalize_key(key))
end

#[]=(key, value) ⇒ Object



75
76
77
# File 'lib/tina4/request.rb', line 75

def []=(key, value)
  super(normalize_key(key), value)
end

#delete(key, &block) ⇒ Object



90
91
92
# File 'lib/tina4/request.rb', line 90

def delete(key, &block)
  super(normalize_key(key), &block)
end

#fetch(key, *args, &block) ⇒ Object



79
80
81
# File 'lib/tina4/request.rb', line 79

def fetch(key, *args, &block)
  super(normalize_key(key), *args, &block)
end

#key?(key) ⇒ Boolean Also known as: has_key?, include?, member?

Returns:

  • (Boolean)


83
84
85
# File 'lib/tina4/request.rb', line 83

def key?(key)
  super(normalize_key(key))
end

#merge(other) ⇒ Object



98
99
100
101
102
# File 'lib/tina4/request.rb', line 98

def merge(other)
  result = dup
  other.each { |k, v| result[k] = v }
  result
end

#merge!(other) ⇒ Object



104
105
106
107
# File 'lib/tina4/request.rb', line 104

def merge!(other)
  other.each { |k, v| self[k] = v }
  self
end

#store(key, value) ⇒ Object



94
95
96
# File 'lib/tina4/request.rb', line 94

def store(key, value)
  super(normalize_key(key), value)
end