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



50
51
52
# File 'lib/tina4/request.rb', line 50

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

#[]=(key, value) ⇒ Object



54
55
56
# File 'lib/tina4/request.rb', line 54

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

#delete(key, &block) ⇒ Object



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

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

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



58
59
60
# File 'lib/tina4/request.rb', line 58

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

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

Returns:

  • (Boolean)


62
63
64
# File 'lib/tina4/request.rb', line 62

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

#merge(other) ⇒ Object



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

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

#merge!(other) ⇒ Object



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

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

#store(key, value) ⇒ Object



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

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