add auth_store

master
Kanezoh 2021-11-23 14:50:40 +09:00
parent 9a2c0fbb33
commit 6e00f00c5f
1 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,34 @@
class Mechanize
module HTTP
# This class store info for HTTP Authentication.
class AuthStore
getter auth_accounts : Hash(URI, Tuple(String, String))
def initialize
@auth_accounts = Hash(URI, Tuple(String, String)).new
end
def add_auth(uri, user, pass)
unless uri.is_a?(URI)
uri = URI.new(uri)
end
#uri += '/'
uri.user = nil
uri.password = nil
auth_accounts[uri] = {user, pass}
end ##
# Retrieves credentials for +realm+ on the server at +uri+.
def credentials_for(uri, realm) : Tuple(String)
unless uri.is_a?(URI)
uri = URI.new(uri)
end
#uri += '/'
uri.user = nil
uri.password = nil
auth_accounts[uri]
end
end
end
end