MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / ForwardToUpstreamProxy

Method ForwardToUpstreamProxy

libi2pd_client/HTTPProxy.cpp:547–612  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

545 }
546
547 void HTTPReqHandler::ForwardToUpstreamProxy()
548 {
549 LogPrint(eLogDebug, "HTTPProxy: Forwarded to upstream");
550
551 /* build http request */
552 m_ClientRequestURL = m_RequestURL;
553 LogPrint(eLogDebug, "HTTPProxy: ", m_ClientRequestURL.host);
554 m_ClientRequestURL.schema = "";
555 m_ClientRequestURL.host = "";
556 std::string origURI = m_ClientRequest.uri; // TODO: what do we need to change uri for?
557 m_ClientRequest.uri = m_ClientRequestURL.to_string();
558
559 /* update User-Agent to ESR version of Firefox, same as Tor Browser below version 13, for non-HTTPS connections */
560 if(m_ClientRequest.method != "CONNECT" && !m_SendUserAgent)
561 m_ClientRequest.UpdateHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:109.0) Gecko/20100101 Firefox/115.0");
562
563 m_ClientRequest.write(m_ClientRequestBuffer);
564 m_ClientRequestBuffer << m_recv_buf.substr(m_req_len);
565
566 /* assume http if empty schema */
567 if (m_ProxyURL.schema == "" || m_ProxyURL.schema == "http")
568 {
569 /* handle upstream http proxy */
570 if (!m_ProxyURL.port) m_ProxyURL.port = 80;
571 if (m_ProxyURL.is_i2p())
572 {
573 m_ClientRequest.uri = origURI;
574 auto auth = i2p::http::CreateBasicAuthorizationString (m_ProxyURL.user, m_ProxyURL.pass);
575 if (!auth.empty ())
576 {
577 /* remove existing authorization if any */
578 m_ClientRequest.RemoveHeader("Proxy-");
579 /* add own http proxy authorization */
580 m_ClientRequest.AddHeader("Proxy-Authorization", auth);
581 }
582 m_send_buf = m_ClientRequest.to_string();
583 m_recv_buf.erase(0, m_req_len);
584 m_send_buf.append(m_recv_buf);
585 GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleStreamRequestComplete,
586 shared_from_this(), std::placeholders::_1), m_ProxyURL.host, m_ProxyURL.port);
587 }
588 else
589 {
590 m_proxy_resolver.async_resolve(m_ProxyURL.host, std::to_string(m_ProxyURL.port), std::bind(&HTTPReqHandler::HandleUpstreamProxyResolved, this,
591 std::placeholders::_1, std::placeholders::_2, [&](boost::asio::ip::tcp::endpoint ep)
592 {
593 m_proxysock->async_connect(ep, std::bind(&HTTPReqHandler::HandleUpstreamHTTPProxyConnect, this, std::placeholders::_1));
594 }));
595 }
596 }
597 else if (m_ProxyURL.schema == "socks")
598 {
599 /* handle upstream socks proxy */
600 if (!m_ProxyURL.port) m_ProxyURL.port = 9050; // default to tor default if not specified
601 m_proxy_resolver.async_resolve(m_ProxyURL.host, std::to_string(m_ProxyURL.port), std::bind(&HTTPReqHandler::HandleUpstreamProxyResolved, this,
602 std::placeholders::_1, std::placeholders::_2, [&](boost::asio::ip::tcp::endpoint ep)
603 {
604 m_proxysock->async_connect(ep, std::bind(&HTTPReqHandler::HandleUpstreamSocksProxyConnect, this, std::placeholders::_1));

Callers

nothing calls this directly

Calls 11

LogPrintFunction · 0.85
to_stringFunction · 0.85
trFunction · 0.85
to_stringMethod · 0.80
UpdateHeaderMethod · 0.80
writeMethod · 0.80
is_i2pMethod · 0.80
AddHeaderMethod · 0.80
RemoveHeaderMethod · 0.45
CreateStreamMethod · 0.45

Tested by

no test coverage detected