Sha256: 65f78e4254da9e543e993ff4be1f3630af1a29f613413bc116c9228a85320e46

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'cookiejar'


module RelaxedCookieJar
  module CookieValidation

    def self.included(base)
      base.extend(ClassMethods)

      base.module_eval do
        # This was the only way I found that would reliably override a static
        # method defined on a module, otherwise the old method was called.
        #
        # If you have a better idea of doing this, please create a PR.
        singleton_class.send :alias_method,
                             :compute_search_domains_for_host_with_no_recursion,
                             :compute_search_domains_for_host

        singleton_class.send :alias_method,
                             :compute_search_domains_for_host,
                             :compute_search_domains_for_host_with_recursion
      end
    end

    module ClassMethods

      def compute_search_domains_for_host_with_recursion(host)
        host   = effective_host host
        result = [host]

        if host =~ CookieJar::CookieValidation::IPADDR
          result
        else
          result + recursive_search_domain(host)
        end
      end

      def recursive_search_domain(host)
        m = CookieJar::CookieValidation::BASE_HOSTNAME.match(host)

        result = [".#{host}"]

        if m.nil?
          result
        else
          result + recursive_search_domain(m[1])
        end
      end
    end
  end
end

# The actual monkeypatching.
CookieJar::CookieValidation.include RelaxedCookieJar::CookieValidation

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
relaxed_cookiejar-0.1.0 lib/relaxed_cookiejar/cookie_validation.rb