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



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

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

#[]=(key, value) ⇒ Object



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

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

#delete(key, &block) ⇒ Object



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

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

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



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

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

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

Returns:

  • (Boolean)


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

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

#merge(other) ⇒ Object



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

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

#merge!(other) ⇒ Object



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

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

#store(key, value) ⇒ Object



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

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