| 4312 | #endif |
| 4313 | |
| 4314 | inline bool parse_www_authenticate(const Response &res, |
| 4315 | std::map<std::string, std::string> &auth, |
| 4316 | bool is_proxy) { |
| 4317 | auto auth_key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate"; |
| 4318 | if (res.has_header(auth_key)) { |
| 4319 | static auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~"); |
| 4320 | auto s = res.get_header_value(auth_key); |
| 4321 | auto pos = s.find(' '); |
| 4322 | if (pos != std::string::npos) { |
| 4323 | auto type = s.substr(0, pos); |
| 4324 | if (type == "Basic") { |
| 4325 | return false; |
| 4326 | } else if (type == "Digest") { |
| 4327 | s = s.substr(pos + 1); |
| 4328 | auto beg = std::sregex_iterator(s.begin(), s.end(), re); |
| 4329 | for (auto i = beg; i != std::sregex_iterator(); ++i) { |
| 4330 | auto m = *i; |
| 4331 | auto key = s.substr(static_cast<size_t>(m.position(1)), |
| 4332 | static_cast<size_t>(m.length(1))); |
| 4333 | auto val = m.length(2) > 0 |
| 4334 | ? s.substr(static_cast<size_t>(m.position(2)), |
| 4335 | static_cast<size_t>(m.length(2))) |
| 4336 | : s.substr(static_cast<size_t>(m.position(3)), |
| 4337 | static_cast<size_t>(m.length(3))); |
| 4338 | auth[key] = val; |
| 4339 | } |
| 4340 | return true; |
| 4341 | } |
| 4342 | } |
| 4343 | } |
| 4344 | return false; |
| 4345 | } |
| 4346 | |
| 4347 | // https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c/440240#answer-440240 |
| 4348 | inline std::string random_string(size_t length) { |
no test coverage detected