class Jeanine::Headers

Constants

CGI_VARIABLES
DEFAULT
HTTP_HEADER

Public Class Methods

new(request) click to toggle source
# File lib/jeanine/headers.rb, line 30
def initialize(request)
  @req = request
end

Public Instance Methods

[](key) click to toggle source
# File lib/jeanine/headers.rb, line 34
def [](key)
  @req.get_header env_name(key)
end
each(&block) click to toggle source
# File lib/jeanine/headers.rb, line 53
def each(&block)
  @req.each_header(&block)
end
fetch(key, default = DEFAULT) { || ... } click to toggle source
# 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
include?(key)
Alias for: key?
key?(key) click to toggle source
# File lib/jeanine/headers.rb, line 38
def key?(key)
  @req.has_header? env_name(key)
end
Also aliased as: include?
to_h() click to toggle source
# File lib/jeanine/headers.rb, line 57
def to_h
  obj = {}
  each do |k,v|
    obj[k] = v
  end
  obj
end

Private Instance Methods

env_name(key) click to toggle source
# File lib/jeanine/headers.rb, line 67
def env_name(key)
  key = key.to_s
  if HTTP_HEADER.match?(key)
    key = key.upcase.tr("-", "_")
    key = "HTTP_" + key unless CGI_VARIABLES.include?(key)
  end
  key
end