2021-07-02 16:44:48 +02:00
|
|
|
#ifndef CPR_PROXYAUTH_H
|
|
|
|
#define CPR_PROXYAUTH_H
|
|
|
|
|
|
|
|
#include <initializer_list>
|
|
|
|
#include <map>
|
2023-08-05 20:31:33 +02:00
|
|
|
#include <string>
|
2021-07-02 16:44:48 +02:00
|
|
|
|
|
|
|
#include "cpr/auth.h"
|
|
|
|
#include "cpr/util.h"
|
|
|
|
|
|
|
|
namespace cpr {
|
2023-08-05 20:31:33 +02:00
|
|
|
class ProxyAuthentication;
|
|
|
|
|
2021-07-02 16:44:48 +02:00
|
|
|
class EncodedAuthentication {
|
2023-08-05 20:31:33 +02:00
|
|
|
friend ProxyAuthentication;
|
|
|
|
|
2021-07-02 16:44:48 +02:00
|
|
|
public:
|
2023-08-05 20:31:33 +02:00
|
|
|
EncodedAuthentication() = default;
|
|
|
|
EncodedAuthentication(const std::string& p_username, const std::string& p_password) : username(util::urlEncode(p_username)), password(util::urlEncode(p_password)) {}
|
2021-07-02 16:44:48 +02:00
|
|
|
EncodedAuthentication(const EncodedAuthentication& other) = default;
|
|
|
|
EncodedAuthentication(EncodedAuthentication&& old) noexcept = default;
|
2023-08-05 20:31:33 +02:00
|
|
|
virtual ~EncodedAuthentication() noexcept;
|
2021-07-02 16:44:48 +02:00
|
|
|
|
|
|
|
EncodedAuthentication& operator=(EncodedAuthentication&& old) noexcept = default;
|
|
|
|
EncodedAuthentication& operator=(const EncodedAuthentication& other) = default;
|
|
|
|
|
2023-08-05 20:31:33 +02:00
|
|
|
[[nodiscard]] const std::string& GetUsername() const;
|
|
|
|
[[nodiscard]] const std::string& GetPassword() const;
|
2021-07-02 16:44:48 +02:00
|
|
|
|
2023-08-05 20:31:33 +02:00
|
|
|
private:
|
|
|
|
std::string username;
|
|
|
|
std::string password;
|
2021-07-02 16:44:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class ProxyAuthentication {
|
|
|
|
public:
|
|
|
|
ProxyAuthentication() = default;
|
|
|
|
ProxyAuthentication(const std::initializer_list<std::pair<const std::string, EncodedAuthentication>>& auths) : proxyAuth_{auths} {}
|
2023-08-05 20:31:33 +02:00
|
|
|
explicit ProxyAuthentication(const std::map<std::string, EncodedAuthentication>& auths) : proxyAuth_{auths} {}
|
2021-07-02 16:44:48 +02:00
|
|
|
|
2023-08-05 20:31:33 +02:00
|
|
|
[[nodiscard]] bool has(const std::string& protocol) const;
|
|
|
|
const char* GetUsername(const std::string& protocol);
|
|
|
|
const char* GetPassword(const std::string& protocol);
|
2021-07-02 16:44:48 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::map<std::string, EncodedAuthentication> proxyAuth_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cpr
|
|
|
|
|
|
|
|
#endif
|