Sha256: 2bfa562c6a173a5fc69578eb3268e4a4679b309059c3c1c9bdbbfc91afe2cee6

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

class Mechanize::HTTP

  AuthChallenge = Struct.new :scheme, :params

  ##
  # A parsed WWW-Authenticate header

  class AuthChallenge

    ##
    # :attr_accessor: scheme
    #
    # The authentication scheme

    ##
    # :attr_accessor: params
    #
    # The authentication parameters

    ##
    # :method: initialize(scheme = nil, params = nil)
    #
    # Creates a new AuthChallenge header with the given scheme and parameters

    ##
    # Retrieves +param+ from the params list

    def [] param
      params[param]
    end

    ##
    # Constructs an AuthRealm for this challenge

    def realm uri
      case scheme
      when 'Basic' then
        raise ArgumentError, "provide uri for Basic authentication" unless uri
        Mechanize::HTTP::AuthRealm.new scheme, uri + '/', self['realm']
      when 'Digest' then
        Mechanize::HTTP::AuthRealm.new scheme, uri + '/', self['realm']
      else
        raise Mechanize::Error, "unknown HTTP authentication scheme #{scheme}"
      end
    end

    ##
    # The name of the realm for this challenge

    def realm_name
      params['realm'] if Hash === params # NTLM has a string for params
    end

    ##
    # The reconstructed, normalized challenge

    def to_s
      auth_params = params.map { |name, value| "#{name}=\"#{value}\"" }

      "#{scheme} #{auth_params.join ', '}"
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mechanize-2.5.1 lib/mechanize/http/auth_challenge.rb
mechanize-2.5 lib/mechanize/http/auth_challenge.rb
mechanize-2.4 lib/mechanize/http/auth_challenge.rb