Class: OpenapiParameters::HeadersHash

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_parameters/headers_hash.rb

Overview

This is a wrapper around the Rack env hash that allows us to access headers with headers names

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ HeadersHash

This was copied from this Rack::Request PR: github.com/rack/rack/pull/1881 It is not yet released in Rack, so we copied it here.



8
9
10
# File 'lib/openapi_parameters/headers_hash.rb', line 8

def initialize(env)
  @env = env
end

Instance Method Details

#[](k) ⇒ Object



12
13
14
# File 'lib/openapi_parameters/headers_hash.rb', line 12

def [](k)
  @env[header_to_env_key(k)]
end

#header_to_env_key(k) ⇒ Object



20
21
22
23
24
25
# File 'lib/openapi_parameters/headers_hash.rb', line 20

def header_to_env_key(k)
  k = k.upcase
  k.tr!('-', '_')
  k = "HTTP_#{k}" unless %w[CONTENT_LENGTH CONTENT_TYPE].include?(k)
  k
end

#key?(k) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/openapi_parameters/headers_hash.rb', line 16

def key?(k)
  @env.key?(header_to_env_key(k))
end