Class: Jeanine::Headers

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/jeanine/headers.rb

Constant Summary collapse

CGI_VARIABLES =
Set.new(%W[
  AUTH_TYPE
  CONTENT_LENGTH
  CONTENT_TYPE
  GATEWAY_INTERFACE
  HTTPS
  PATH_INFO
  PATH_TRANSLATED
  QUERY_STRING
  REMOTE_ADDR
  REMOTE_HOST
  REMOTE_IDENT
  REMOTE_USER
  REQUEST_METHOD
  SCRIPT_NAME
  SERVER_NAME
  SERVER_PORT
  SERVER_PROTOCOL
  SERVER_SOFTWARE
]).freeze
HTTP_HEADER =
/\A[A-Za-z0-9-]+\z/
DEFAULT =
Object.new

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Headers

Returns a new instance of Headers.



30
31
32
# File 'lib/jeanine/headers.rb', line 30

def initialize(request)
  @req = request
end

Instance Method Details

#[](key) ⇒ Object



34
35
36
# File 'lib/jeanine/headers.rb', line 34

def [](key)
  @req.get_header env_name(key)
end

#each(&block) ⇒ Object



53
54
55
# File 'lib/jeanine/headers.rb', line 53

def each(&block)
  @req.each_header(&block)
end

#fetch(key, default = DEFAULT) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/jeanine/headers.rb', line 45

def fetch(key, default = DEFAULT)
  @req.fetch_header(env_name(key)) do
    return default unless default == DEFAULT
    return yield if block_given?
    raise KeyError, key
  end
end

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

Returns:

  • (Boolean)


38
39
40
# File 'lib/jeanine/headers.rb', line 38

def key?(key)
  @req.has_header? env_name(key)
end

#to_hObject



57
58
59
60
61
62
63
# File 'lib/jeanine/headers.rb', line 57

def to_h
  obj = {}
  each do |k,v|
    obj[k] = v
  end
  obj
end