| 4692 | #endif |
| 4693 | |
| 4694 | inline bool parse_www_authenticate(const Response &res, |
| 4695 | std::map<std::string, std::string> &auth, |
| 4696 | bool is_proxy) { |
| 4697 | auto auth_key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate"; |
| 4698 | if (res.has_header(auth_key)) { |
| 4699 | static auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~"); |
| 4700 | auto s = res.get_header_value(auth_key); |
| 4701 | auto pos = s.find(' '); |
| 4702 | if (pos != std::string::npos) { |
| 4703 | auto type = s.substr(0, pos); |
| 4704 | if (type == "Basic") { |
| 4705 | return false; |
| 4706 | } else if (type == "Digest") { |
| 4707 | s = s.substr(pos + 1); |
| 4708 | auto beg = std::sregex_iterator(s.begin(), s.end(), re); |
| 4709 | for (auto i = beg; i != std::sregex_iterator(); ++i) { |
| 4710 | auto m = *i; |
| 4711 | auto key = s.substr(static_cast<size_t>(m.position(1)), |
| 4712 | static_cast<size_t>(m.length(1))); |
| 4713 | auto val = m.length(2) > 0 |
| 4714 | ? s.substr(static_cast<size_t>(m.position(2)), |
| 4715 | static_cast<size_t>(m.length(2))) |
| 4716 | : s.substr(static_cast<size_t>(m.position(3)), |
| 4717 | static_cast<size_t>(m.length(3))); |
| 4718 | auth[key] = val; |
| 4719 | } |
| 4720 | return true; |
| 4721 | } |
| 4722 | } |
| 4723 | } |
| 4724 | return false; |
| 4725 | } |
| 4726 | |
| 4727 | // https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c/440240#answer-440240 |
| 4728 | inline std::string random_string(size_t length) { |
no test coverage detected