From 6e00f00c5fb4abbc3b8089d4240287c2f5e595d9 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Tue, 23 Nov 2021 14:50:40 +0900 Subject: [PATCH] add auth_store --- src/mechanize/http/auth_store.cr | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/mechanize/http/auth_store.cr diff --git a/src/mechanize/http/auth_store.cr b/src/mechanize/http/auth_store.cr new file mode 100644 index 0000000..7167dbc --- /dev/null +++ b/src/mechanize/http/auth_store.cr @@ -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