Sha256: 0bf6722fd01d11b909421c550f467cff53dbef4039f81cc246f6c2df353bcbc1

Contents?: true

Size: 1.61 KB

Versions: 5

Compression:

Stored size: 1.61 KB

Contents

require 'action_dispatch/routing/route_set'

module ActionDispatch
  module Routing
    class RouteSet

      # Add a secure option to the rewrite method.
      def url_for_with_secure_option(options = {})
        secure = options.delete(:secure)

        # if secure && ssl check is not disabled, convert to full url with https
        if !secure.nil? && !SslRequirement.disable_ssl_check?
          if secure == true || secure == 1 || secure.to_s.downcase == "true"
            options.merge!({
              :only_path => false,
              :protocol => 'https'
            })

            # if we've been told to use different host for ssl, use it
            unless SslRequirement.ssl_host.nil?
              options.merge! :host => SslRequirement.ssl_host
            end

            # make it non-ssl and use specified options
          else
            options.merge!({
              :protocol => 'http'
            })
          end
        end

        url_for_without_secure_option(options)
      end

      # if full URL is requested for http and we've been told to use a
      # non-ssl host override, then use it
      def url_for_with_non_ssl_host(options)
        if !options[:only_path] && !SslRequirement.non_ssl_host.nil?
          if !(/^https/ =~ (options[:protocol] || @request.protocol))
            options.merge! :host => SslRequirement.non_ssl_host
          end
        end
        url_for_without_non_ssl_host(options)
      end

      # want with_secure_option to get run first (so chain it last)
      alias_method_chain :url_for, :non_ssl_host
      alias_method_chain :url_for, :secure_option
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bartt-ssl_requirement-1.2.4 lib/url_for.rb
bartt-ssl_requirement-1.2.3 lib/url_for.rb
bartt-ssl_requirement-1.2.2 lib/url_for.rb
bartt-ssl_requirement-1.2.1 lib/url_for.rb
bartt-ssl_requirement-1.2.0 lib/url_for.rb