Class: Aldebaran::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/aldebaran/base.rb

Overview

The request object. See Rack::Request for more info: rack.rubyforge.org/doc/classes/Rack/Request.html

Instance Method Summary collapse

Instance Method Details

#acceptObject

Returns an array of acceptable media types for the response



20
21
22
23
24
25
# File 'lib/aldebaran/base.rb', line 20

def accept
  @env['aldebaran.accept'] ||= begin
    entries = @env['HTTP_ACCEPT'].to_s.split(',')
    entries.map { |e| accept_entry(e) }.sort_by(&:last).map(&:first)
  end
end

#forwarded?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/aldebaran/base.rb', line 39

def forwarded?
  @env.include? "HTTP_X_FORWARDED_HOST"
end

#idempotent?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/aldebaran/base.rb', line 47

def idempotent?
  safe? or put? or delete?
end

#preferred_type(*types) ⇒ Object Also known as: accept?



27
28
29
30
31
32
33
34
# File 'lib/aldebaran/base.rb', line 27

def preferred_type(*types)
  return accept.first if types.empty?
  types.flatten!
  accept.detect do |pattern|
    type = types.detect { |t| File.fnmatch(pattern, t) }
    return type if type
  end
end

#safe?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/aldebaran/base.rb', line 43

def safe?
  get? or head? or options? or trace?
end