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



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

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

#[]=(key, value) ⇒ Object



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

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

#delete(key, &block) ⇒ Object



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

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

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



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

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

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

Returns:

  • (Boolean)


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

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

#merge(other) ⇒ Object



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

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

#merge!(other) ⇒ Object



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

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

#store(key, value) ⇒ Object



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

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