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

Method handle_request

examples/server/httplib.h:6471–6530  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6469}
6470
6471inline bool ClientImpl::handle_request(Stream &strm, Request &req,
6472 Response &res, bool close_connection,
6473 Error &error) {
6474 if (req.path.empty()) {
6475 error = Error::Connection;
6476 return false;
6477 }
6478
6479 auto req_save = req;
6480
6481 bool ret;
6482
6483 if (!is_ssl() && !proxy_host_.empty() && proxy_port_ != -1) {
6484 auto req2 = req;
6485 req2.path = "http://" + host_and_port_ + req.path;
6486 ret = process_request(strm, req2, res, close_connection, error);
6487 req = req2;
6488 req.path = req_save.path;
6489 } else {
6490 ret = process_request(strm, req, res, close_connection, error);
6491 }
6492
6493 if (!ret) { return false; }
6494
6495 if (300 < res.status && res.status < 400 && follow_location_) {
6496 req = req_save;
6497 ret = redirect(req, res, error);
6498 }
6499
6500#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
6501 if ((res.status == 401 || res.status == 407) &&
6502 req.authorization_count_ < 5) {
6503 auto is_proxy = res.status == 407;
6504 const auto &username =
6505 is_proxy ? proxy_digest_auth_username_ : digest_auth_username_;
6506 const auto &password =
6507 is_proxy ? proxy_digest_auth_password_ : digest_auth_password_;
6508
6509 if (!username.empty() && !password.empty()) {
6510 std::map<std::string, std::string> auth;
6511 if (detail::parse_www_authenticate(res, auth, is_proxy)) {
6512 Request new_req = req;
6513 new_req.authorization_count_ += 1;
6514 new_req.headers.erase(is_proxy ? "Proxy-Authorization"
6515 : "Authorization");
6516 new_req.headers.insert(detail::make_digest_authentication_header(
6517 req, auth, new_req.authorization_count_, detail::random_string(10),
6518 username, password, is_proxy));
6519
6520 Response new_res;
6521
6522 ret = send(new_req, new_res, error);
6523 if (ret) { res = new_res; }
6524 }
6525 }
6526 }
6527#endif
6528

Callers

nothing calls this directly

Calls 6

redirectFunction · 0.85
parse_www_authenticateFunction · 0.85
random_stringFunction · 0.70
emptyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected