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

Method connect_with_proxy

examples/server/httplib.h:8003–8058  ·  view source on GitHub ↗

Assumes that socket_mutex_ is locked and that there are no requests in flight

Source from the content-addressed store, hash-verified

8001
8002// Assumes that socket_mutex_ is locked and that there are no requests in flight
8003inline bool SSLClient::connect_with_proxy(Socket &socket, Response &res,
8004 bool &success, Error &error) {
8005 success = true;
8006 Response res2;
8007 if (!detail::process_client_socket(
8008 socket.sock, read_timeout_sec_, read_timeout_usec_,
8009 write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) {
8010 Request req2;
8011 req2.method = "CONNECT";
8012 req2.path = host_and_port_;
8013 return process_request(strm, req2, res2, false, error);
8014 })) {
8015 // Thread-safe to close everything because we are assuming there are no
8016 // requests in flight
8017 shutdown_ssl(socket, true);
8018 shutdown_socket(socket);
8019 close_socket(socket);
8020 success = false;
8021 return false;
8022 }
8023
8024 if (res2.status == 407) {
8025 if (!proxy_digest_auth_username_.empty() &&
8026 !proxy_digest_auth_password_.empty()) {
8027 std::map<std::string, std::string> auth;
8028 if (detail::parse_www_authenticate(res2, auth, true)) {
8029 Response res3;
8030 if (!detail::process_client_socket(
8031 socket.sock, read_timeout_sec_, read_timeout_usec_,
8032 write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) {
8033 Request req3;
8034 req3.method = "CONNECT";
8035 req3.path = host_and_port_;
8036 req3.headers.insert(detail::make_digest_authentication_header(
8037 req3, auth, 1, detail::random_string(10),
8038 proxy_digest_auth_username_, proxy_digest_auth_password_,
8039 true));
8040 return process_request(strm, req3, res3, false, error);
8041 })) {
8042 // Thread-safe to close everything because we are assuming there are
8043 // no requests in flight
8044 shutdown_ssl(socket, true);
8045 shutdown_socket(socket);
8046 close_socket(socket);
8047 success = false;
8048 return false;
8049 }
8050 }
8051 } else {
8052 res = res2;
8053 return false;
8054 }
8055 }
8056
8057 return true;
8058}
8059
8060inline bool SSLClient::load_certs() {

Callers 1

send_Method · 0.80

Calls 8

process_client_socketFunction · 0.85
shutdown_socketFunction · 0.85
close_socketFunction · 0.85
parse_www_authenticateFunction · 0.85
random_stringFunction · 0.70
emptyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected