| 1 | #ifndef CPR_PROXYAUTH_H |
|---|---|
| 2 | #define CPR_PROXYAUTH_H |
| 3 | |
| 4 | #include <initializer_list> |
| 5 | #include <map> |
| 6 | |
| 7 | #include "cpr/auth.h" |
| 8 | #include "cpr/util.h" |
| 9 | |
| 10 | namespace cpr { |
| 11 | class EncodedAuthentication { |
| 12 | public: |
| 13 | EncodedAuthentication() : auth_string_{""} {} |
| 14 | EncodedAuthentication(std::string username, std::string password) : auth_string_{cpr::util::urlEncode(s: std::move(username)) + ":"+ cpr::util::urlEncode(s: std::move(password))} {} |
| 15 | EncodedAuthentication(const EncodedAuthentication& other) = default; |
| 16 | EncodedAuthentication(EncodedAuthentication&& old) noexcept = default; |
| 17 | virtual ~EncodedAuthentication() noexcept; |
| 18 | |
| 19 | EncodedAuthentication& operator=(EncodedAuthentication&& old) noexcept = default; |
| 20 | EncodedAuthentication& operator=(const EncodedAuthentication& other) = default; |
| 21 | |
| 22 | const char* GetAuthString() const noexcept; |
| 23 | |
| 24 | protected: |
| 25 | std::string auth_string_; |
| 26 | }; |
| 27 | |
| 28 | class ProxyAuthentication { |
| 29 | public: |
| 30 | ProxyAuthentication() = default; |
| 31 | ProxyAuthentication(const std::initializer_list<std::pair<const std::string, EncodedAuthentication>>& auths) : proxyAuth_{auths} {} |
| 32 | ProxyAuthentication(const std::map<std::string, EncodedAuthentication>& auths) : proxyAuth_{auths} {} |
| 33 | |
| 34 | bool has(const std::string& protocol) const; |
| 35 | const char* operator[](const std::string& protocol); |
| 36 | |
| 37 | private: |
| 38 | std::map<std::string, EncodedAuthentication> proxyAuth_; |
| 39 | }; |
| 40 | |
| 41 | } // namespace cpr |
| 42 | |
| 43 | #endif |
| 44 |