Class: Rad::Http::Request
- Defined in:
- lib/rad/http/_request.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cookies_with_memory ⇒ Object
-
#domain(tld_length = 1) ⇒ Object
Returns the domain part of a host, such as “rubyonrails.org” in “www.rubyonrails.org”.
- #from_browser? ⇒ Boolean
- #normalized_domain ⇒ Object
-
#raw_params ⇒ Object
Need this to access original, not normalized with Utils.normalize_params params.
-
#subdomains(tld_length = 1) ⇒ Object
Returns all the subdomains as an array, so
["dev", "www"]
would be returned for “dev.www.rubyonrails.org”.
Class Method Details
.stub(url = '/') ⇒ Object
61 62 63 64 |
# File 'lib/rad/http/_request.rb', line 61 def stub url = '/' env = stub_environment(url) Rad::Http::Request.new env end |
.stub_environment(url = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rad/http/_request.rb', line 66 def stub_environment url = nil env = { 'rack.url_scheme' => 'http', 'PATH_INFO' => '/', 'HTTP_HOST' => 'test.com', 'rack.input' => StringIO.new } if url uri = Uri.parse url env.merge!( 'HTTP_HOST' => %(#{uri.host}#{":#{uri.port}" if uri.port.present?}), # 'REQUEST_PATH' => uri.path, 'PATH_INFO' => uri.path, # 'REQUEST_URI' => uri.path, 'QUERY_STRING' => uri.query ) end env end |
Instance Method Details
#cookies_with_memory ⇒ Object
30 31 32 |
# File 'lib/rad/http/_request.rb', line 30 def @cookies_with_memory ||= end |
#domain(tld_length = 1) ⇒ Object
Returns the domain part of a host, such as “rubyonrails.org” in “www.rubyonrails.org”. You can specify a different tld_length
, such as 2 to catch rubyonrails.co.uk in “www.rubyonrails.co.uk”.
24 25 26 27 28 |
# File 'lib/rad/http/_request.rb', line 24 def domain(tld_length = 1) return nil unless named_host?(host) host.split('.').last(1 + tld_length).join('.') end |
#from_browser? ⇒ Boolean
40 41 42 43 44 |
# File 'lib/rad/http/_request.rb', line 40 def from_browser? # format = workspace.params.format # (format.present? and !rad.http.browser_generated_formats.include?(format)) or content_type.present? and rad.http.browser_generated_types.include?(content_type.downcase) end |
#normalized_domain ⇒ Object
35 36 37 38 |
# File 'lib/rad/http/_request.rb', line 35 def normalized_domain return nil unless named_host?(host) host.sub('www.', '').downcase end |
#raw_params ⇒ Object
Need this to access original, not normalized with Utils.normalize_params params
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rad/http/_request.rb', line 49 def raw_params post = {} @env['rack.input'].read.split('&').each do |tuple| k, v = tuple.split('=') post[Rack::Utils.unescape(k || "")] = Rack::Utils.unescape(v || "") end self.GET.merge(post) rescue EOFError self.GET end |
#subdomains(tld_length = 1) ⇒ Object
Returns all the subdomains as an array, so ["dev", "www"]
would be returned for “dev.www.rubyonrails.org”. You can specify a different tld_length
, such as 2 to catch ["www"]
instead of ["www", "rubyonrails"]
in “www.rubyonrails.co.uk”.
15 16 17 18 19 |
# File 'lib/rad/http/_request.rb', line 15 def subdomains(tld_length = 1) return [] unless named_host?(host) parts = host.split('.') parts[0..-(tld_length+2)] end |