def connect(path, options = {})
      options = options.dup

      if conditions = options.delete(:conditions)
        conditions = conditions.dup
        subdomain = conditions.delete(:subdomain)
        method = Array.wrap(conditions.delete(:method))
        method.map! { |m|
          if m == :head
            raise ArgumentError, "HTTP method HEAD is invalid in route conditions. Rails processes HEAD requests the same as GETs, returning just the response headers"
          end

          unless ActionDispatch::Routing::HTTP_METHODS.include?(m)
            raise ArgumentError, "Invalid HTTP method specified in route conditions"
          end

          m.to_s.dasherize.upcase
        }
      end

      path_prefix = options.delete(:path_prefix)
      name_prefix = options.delete(:name_prefix)
      namespace  = options.delete(:namespace)

      name = options.delete(:_name)
      name = "#{name_prefix}#{name}" if name_prefix

      requirements = options.delete(:requirements) || {}
      defaults = options.delete(:defaults) || {}
      options.each do |k, v|
        if v.is_a?(Regexp)
          if value = options.delete(k)
            requirements[k.to_sym] = value
          end
        else
          value = options.delete(k)
          defaults[k.to_sym] = value.is_a?(Symbol) ? value : value.to_param
        end
      end

      requirements.each do |_, requirement|
        if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
          raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
        end
        if requirement.multiline?
          raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
        end
      end

      requirements[:controller] ||= @set.controller_constraints

      if defaults[:controller]
        defaults[:action] ||= 'index'
        defaults[:controller] = defaults[:controller].to_s
        defaults[:controller] = "#{namespace}#{defaults[:controller]}" if namespace
      end

      if defaults[:action]
        defaults[:action] = defaults[:action].to_s
      end

      if path.is_a?(String)
        path = "#{path_prefix}/#{path}" if path_prefix
        path = path.gsub('.:format', '(.:format)')
        path = optionalize_trailing_dynamic_segments(path, requirements, defaults)
        glob = $1.to_sym if path =~ /\/\*(\w+)$/
        path = normalize_path(path)

        if glob && !defaults[glob].blank?
          raise ActionController::RoutingError, "paths cannot have non-empty default values"
        end
      end

      app = ActionDispatch::Routing::RouteSet::Dispatcher.new(:defaults => defaults, :glob => glob)

      conditions = {}
      conditions[:request_method] = method if method && !method.empty?
      conditions[:path_info] = path if path
      conditions[:subdomain] = subdomain if subdomain

      @set.add_route(app, conditions, requirements, defaults, name)
    end
def connect(path, options = {})
      options = options.dup

      if conditions = options.delete(:conditions)
        conditions = conditions.dup
        subdomain = conditions.delete(:subdomain)
        method = Array.wrap(conditions.delete(:method))
        method.map! { |m|
          if m == :head
            raise ArgumentError, "HTTP method HEAD is invalid in route conditions. Rails processes HEAD requests the same as GETs, returning just the response headers"
          end

          unless ActionDispatch::Routing::HTTP_METHODS.include?(m)
            raise ArgumentError, "Invalid HTTP method specified in route conditions"
          end

          m.to_s.dasherize.upcase
        }
      end

      path_prefix = options.delete(:path_prefix)
      name_prefix = options.delete(:name_prefix)
      namespace  = options.delete(:namespace)

      name = options.delete(:_name)
      name = "#{name_prefix}#{name}" if name_prefix

      requirements = options.delete(:requirements) || {}
      defaults = options.delete(:defaults) || {}
      options.each do |k, v|
        if v.is_a?(Regexp)
          if value = options.delete(k)
            requirements[k.to_sym] = value
          end
        else
          value = options.delete(k)
          defaults[k.to_sym] = value.is_a?(Symbol) ? value : value.to_param
        end
      end

      requirements.each do |_, requirement|
        if requirement.source =~ %r{\A(\\A|\^)|(\\Z|\\z|\$)\Z}
          raise ArgumentError, "Regexp anchor characters are not allowed in routing requirements: #{requirement.inspect}"
        end
        if requirement.multiline?
          raise ArgumentError, "Regexp multiline option not allowed in routing requirements: #{requirement.inspect}"
        end
      end

      requirements[:controller] ||= @set.controller_constraints

      if defaults[:controller]
        defaults[:action] ||= 'index'
        defaults[:controller] = defaults[:controller].to_s
        defaults[:controller] = "#{namespace}#{defaults[:controller]}" if namespace
      end

      if defaults[:action]
        defaults[:action] = defaults[:action].to_s
      end

      if path.is_a?(String)
        path = "#{path_prefix}/#{path}" if path_prefix
        path = path.gsub('.:format', '(.:format)')
        path = optionalize_trailing_dynamic_segments(path, requirements, defaults)
        glob = $1.to_sym if path =~ /\/\*(\w+)$/
        path = normalize_path(path)

        if glob && !defaults[glob].blank?
          raise ActionController::RoutingError, "paths cannot have non-empty default values"
        end
      end

      app = ActionDispatch::Routing::RouteSet::Dispatcher.new(:defaults => defaults, :glob => glob)

      conditions = {}
      conditions[:request_method] = method if method && !method.empty?
      conditions[:path_info] = path if path
      conditions[:subdomain] = subdomain if subdomain

      @set.add_route(app, conditions, requirements, defaults, name)
    end
:nodoc: