Sha256: c0358de4da0a1b3f9ad81cb47b3f86a3a0a5724198190d4c4e6d4b59ee35b4a5

Contents?: true

Size: 1.65 KB

Versions: 12

Compression:

Stored size: 1.65 KB

Contents

class Rad::Http::Request < Rack::Request
  # Returns an array of acceptable media types for the response
  # def accept
  #   @env['HTTP_ACCEPT'].to_s.split(',').map { |a| a.split(';')[0].strip }
  # end
  # 
  # def secure?
  #   (@env['HTTP_X_FORWARDED_PROTO'] || @env['rack.url_scheme']) == 'https'
  # end


  # Returns all the \subdomains as an array, so <tt>["dev", "www"]</tt> would be
  # returned for "dev.www.rubyonrails.org". You can specify a different <tt>tld_length</tt>,
  # such as 2 to catch <tt>["www"]</tt> instead of <tt>["www", "rubyonrails"]</tt>
  # in "www.rubyonrails.co.uk".
  def subdomains(tld_length = 1)
    return [] unless named_host?(host)
    parts = host.split('.')
    parts[0..-(tld_length+2)]
  end


  # Returns the \domain part of a \host, such as "rubyonrails.org" in "www.rubyonrails.org". You can specify
  # a different <tt>tld_length</tt>, such as 2 to catch rubyonrails.co.uk in "www.rubyonrails.co.uk".
  def domain(tld_length = 1)
    return nil unless named_host?(host)

    host.split('.').last(1 + tld_length).join('.')
  end

  def cookies_with_memory
    @cookies_with_memory ||= cookies_without_memory
  end
  alias_method_chain :cookies, :memory
  
  def normalized_domain
    return nil unless named_host?(host)
    host.sub('www.', '').downcase
    # subdomains = request.subdomains.select{|n| n != 'www'}
    # subdomain = subdomains.last
    # pure_domain = request.domain.sub(/\A#{subdomains.join(".")}\./, "")
    # 
    # domain = subdomain.blank? ? pure_domain : "#{subdomain}.#{pure_domain}"
  end

  protected    
    def named_host?(host)
      !(host.nil? || /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.match(host))
    end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rad_core-0.0.25 lib/rad/http/_request.rb
rad_core-0.0.24 lib/rad/http/_request.rb
rad_core-0.0.23 lib/rad/http/_request.rb
rad_core-0.0.22 lib/rad/http/_request.rb
rad_core-0.0.21 lib/rad/http/_request.rb
rad_core-0.0.20 lib/rad/http/_request.rb
rad_core-0.0.19 lib/rad/http/_request.rb
rad_core-0.0.18 lib/rad/http/_request.rb
rad_core-0.0.17 lib/rad/http/_request.rb
rad_core-0.0.16 lib/rad/http/_request.rb
rad_core-0.0.15 lib/rad/http/_request.rb
rad_core-0.0.14 lib/rad/http/_request.rb