Class: Expressr::Request
- Inherits:
-
Noder::HTTP::Request
- Object
- Noder::HTTP::Request
- Expressr::Request
- Defined in:
- lib/expressr/request.rb
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
Instance Method Summary collapse
- #accepts(types) ⇒ Object
- #accepts_charset(charset) ⇒ Object
- #accepts_language(language) ⇒ Object
- #cookies ⇒ Object
- #fresh? ⇒ Boolean
- #get(name) ⇒ Object (also: #header)
- #host ⇒ Object
-
#initialize(env) ⇒ Request
constructor
A new instance of Request.
- #ip ⇒ Object
- #ips ⇒ Object
- #is?(type) ⇒ Boolean
- #locals ⇒ Object
- #original_url ⇒ Object
- #param(name) ⇒ Object
- #path ⇒ Object
- #protocol ⇒ Object
- #route ⇒ Object
- #secure? ⇒ Boolean
- #signed_cookies ⇒ Object
- #stale? ⇒ Boolean
- #subdomains ⇒ Object
- #url ⇒ Object
- #xhr? ⇒ Boolean
Constructor Details
#initialize(env) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 |
# File 'lib/expressr/request.rb', line 5 def initialize(env) super(env) @params = Hashie::Mash.new(@params) @query = Hashie::Mash.new(@query) end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
3 4 5 |
# File 'lib/expressr/request.rb', line 3 def query @query end |
Instance Method Details
#accepts(types) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/expressr/request.rb', line 35 def accepts(types) types = types.split(', ') if types.is_a?(String) types = [types] unless types.is_a?(Array) @accept_types ||= get('Accept').split(';').first.split(',') (types & @accept_types).first end |
#accepts_charset(charset) ⇒ Object
42 43 44 |
# File 'lib/expressr/request.rb', line 42 def accepts_charset(charset) raise NotImplementedError end |
#accepts_language(language) ⇒ Object
46 47 48 |
# File 'lib/expressr/request.rb', line 46 def accepts_language(language) raise NotImplementedError end |
#cookies ⇒ Object
23 24 25 |
# File 'lib/expressr/request.rb', line 23 def raise NotImplementedError end |
#fresh? ⇒ Boolean
73 74 75 |
# File 'lib/expressr/request.rb', line 73 def fresh? raise NotImplementedError end |
#get(name) ⇒ Object Also known as: header
31 32 33 |
# File 'lib/expressr/request.rb', line 31 def get(name) headers[name] end |
#host ⇒ Object
69 70 71 |
# File 'lib/expressr/request.rb', line 69 def host get('Host').split(':').first end |
#ip ⇒ Object
57 58 59 |
# File 'lib/expressr/request.rb', line 57 def ip @env[:ip] end |
#ips ⇒ Object
61 62 63 |
# File 'lib/expressr/request.rb', line 61 def ips raise NotImplementedError end |
#is?(type) ⇒ Boolean
50 51 52 53 54 55 |
# File 'lib/expressr/request.rb', line 50 def is?(type) content_type_header = headers['Content-Type'] return false if content_type_header.nil? content_types = content_type_header.split('; ') content_types.include?(type) end |
#locals ⇒ Object
97 98 99 |
# File 'lib/expressr/request.rb', line 97 def locals @locals ||= Hashie::Mash.new end |
#original_url ⇒ Object
101 102 103 |
# File 'lib/expressr/request.rb', line 101 def original_url @original_url ||= get_original_url end |
#param(name) ⇒ Object
15 16 17 |
# File 'lib/expressr/request.rb', line 15 def param(name) params[name] end |
#path ⇒ Object
65 66 67 |
# File 'lib/expressr/request.rb', line 65 def path @env[:request_uri] end |
#protocol ⇒ Object
85 86 87 |
# File 'lib/expressr/request.rb', line 85 def protocol @env[:protocol].split('/').first.downcase end |
#route ⇒ Object
19 20 21 |
# File 'lib/expressr/request.rb', line 19 def route raise NotImplementedError end |
#secure? ⇒ Boolean
89 90 91 |
# File 'lib/expressr/request.rb', line 89 def secure? protocol == 'https' end |
#signed_cookies ⇒ Object
27 28 29 |
# File 'lib/expressr/request.rb', line 27 def raise NotImplementedError end |
#stale? ⇒ Boolean
77 78 79 |
# File 'lib/expressr/request.rb', line 77 def stale? raise NotImplementedError end |
#subdomains ⇒ Object
93 94 95 |
# File 'lib/expressr/request.rb', line 93 def subdomains host.split('.')[0..-3].reverse end |
#url ⇒ Object
11 12 13 |
# File 'lib/expressr/request.rb', line 11 def url @url ||= original_url end |
#xhr? ⇒ Boolean
81 82 83 |
# File 'lib/expressr/request.rb', line 81 def xhr? get('X-Requested-With') == 'XMLHttpRequest' end |