Class: Expressr::Request

Inherits:
Noder::HTTP::Request
  • Object
show all
Defined in:
lib/expressr/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#queryObject (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

Raises:

  • (NotImplementedError)


42
43
44
# File 'lib/expressr/request.rb', line 42

def accepts_charset(charset)
  raise NotImplementedError
end

#accepts_language(language) ⇒ Object

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/expressr/request.rb', line 46

def accepts_language(language)
  raise NotImplementedError
end

#cookiesObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/expressr/request.rb', line 23

def cookies
  raise NotImplementedError
end

#fresh?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

#hostObject



69
70
71
# File 'lib/expressr/request.rb', line 69

def host
  get('Host').split(':').first
end

#ipObject



57
58
59
# File 'lib/expressr/request.rb', line 57

def ip
  @env[:ip]
end

#ipsObject

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/expressr/request.rb', line 61

def ips
  raise NotImplementedError
end

#is?(type) ⇒ Boolean

Returns:

  • (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

#localsObject



97
98
99
# File 'lib/expressr/request.rb', line 97

def locals
  @locals ||= Hashie::Mash.new
end

#original_urlObject



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

#pathObject



65
66
67
# File 'lib/expressr/request.rb', line 65

def path
  @env[:request_uri]
end

#protocolObject



85
86
87
# File 'lib/expressr/request.rb', line 85

def protocol
  @env[:protocol].split('/').first.downcase
end

#routeObject

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/expressr/request.rb', line 19

def route
  raise NotImplementedError
end

#secure?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/expressr/request.rb', line 89

def secure?
  protocol == 'https'
end

#signed_cookiesObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/expressr/request.rb', line 27

def signed_cookies
  raise NotImplementedError
end

#stale?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/expressr/request.rb', line 77

def stale?
  raise NotImplementedError
end

#subdomainsObject



93
94
95
# File 'lib/expressr/request.rb', line 93

def subdomains
  host.split('.')[0..-3].reverse
end

#urlObject



11
12
13
# File 'lib/expressr/request.rb', line 11

def url
  @url ||= original_url
end

#xhr?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/expressr/request.rb', line 81

def xhr?
  get('X-Requested-With') == 'XMLHttpRequest'
end