MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / parse_www_authenticate

Function parse_www_authenticate

examples/server/httplib.h:4694–4725  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4692#endif
4693
4694inline 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
4728inline std::string random_string(size_t length) {

Callers 2

handle_requestMethod · 0.85
connect_with_proxyMethod · 0.85

Calls 7

has_headerMethod · 0.80
get_header_valueMethod · 0.80
findMethod · 0.80
substrMethod · 0.80
lengthMethod · 0.80
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected