implement httpproxy.senduseragent

pull/2101/head
orignal 4 weeks ago
parent 2c594dc67a
commit 5073c9637e

@ -117,6 +117,7 @@ namespace config {
("httpproxy.latency.max", value<std::string>()->default_value("0"), "HTTP proxy max latency for tunnels")
("httpproxy.outproxy", value<std::string>()->default_value(""), "HTTP proxy upstream out proxy url")
("httpproxy.addresshelper", value<bool>()->default_value(true), "Enable or disable addresshelper")
("httpproxy.senduseragent", value<bool>()->default_value(false), "Pass through user's User-Agent if enabled. Disabled by deafult")
("httpproxy.i2cp.leaseSetType", value<std::string>()->default_value("3"), "Local destination's LeaseSet type")
("httpproxy.i2cp.leaseSetEncType", value<std::string>()->default_value("0,4"), "Local destination's LeaseSet encryption type")
("httpproxy.i2cp.leaseSetPrivKey", value<std::string>()->default_value(""), "LeaseSet private key")

@ -666,7 +666,9 @@ namespace client
// http proxy
std::string outproxy = section.second.get("outproxy", "");
bool addresshelper = section.second.get("addresshelper", true);
auto tun = std::make_shared<i2p::proxy::HTTPProxy>(name, address, port, outproxy, addresshelper, localDestination);
bool senduseragent = section.second.get("senduseragent", false);
auto tun = std::make_shared<i2p::proxy::HTTPProxy>(name, address, port,
outproxy, addresshelper, senduseragent, localDestination);
clientTunnel = tun;
clientEndpoint = tun->GetLocalEndpoint ();
}
@ -882,6 +884,7 @@ namespace client
uint16_t httpProxyPort; i2p::config::GetOption("httpproxy.port", httpProxyPort);
std::string httpOutProxyURL; i2p::config::GetOption("httpproxy.outproxy", httpOutProxyURL);
bool httpAddresshelper; i2p::config::GetOption("httpproxy.addresshelper", httpAddresshelper);
bool httpSendUserAgent; i2p::config::GetOption("httpproxy.senduseragent", httpSendUserAgent);
if (httpAddresshelper)
i2p::config::GetOption("addressbook.enabled", httpAddresshelper); // addresshelper is not supported without address book
i2p::data::SigningKeyType sigType; i2p::config::GetOption("httpproxy.signaturetype", sigType);
@ -901,7 +904,8 @@ namespace client
}
try
{
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort, httpOutProxyURL, httpAddresshelper, localDestination);
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort,
httpOutProxyURL, httpAddresshelper, httpSendUserAgent, localDestination);
m_HttpProxy->Start();
}
catch (std::exception& e)

@ -80,7 +80,7 @@ namespace proxy {
void AsyncSockRead();
static bool ExtractAddressHelper(i2p::http::URL& url, std::string& jump, bool& confirm);
static bool VerifyAddressHelper (std::string_view jump);
static void SanitizeHTTPRequest(i2p::http::HTTPReq& req);
void SanitizeHTTPRequest(i2p::http::HTTPReq& req);
void SentHTTPFailed(const boost::system::error_code & ecode);
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream);
/* error helpers */
@ -110,7 +110,7 @@ namespace proxy {
std::shared_ptr<boost::asio::ip::tcp::socket> m_proxysock;
boost::asio::ip::tcp::resolver m_proxy_resolver;
std::string m_OutproxyUrl, m_Response;
bool m_Addresshelper;
bool m_Addresshelper, m_SendUserAgent;
i2p::http::URL m_ProxyURL;
i2p::http::URL m_RequestURL;
int m_req_len;
@ -126,7 +126,8 @@ namespace proxy {
m_proxysock(std::make_shared<boost::asio::ip::tcp::socket>(parent->GetService())),
m_proxy_resolver(parent->GetService()),
m_OutproxyUrl(parent->GetOutproxyURL()),
m_Addresshelper(parent->GetHelperSupport()) {}
m_Addresshelper(parent->GetHelperSupport()),
m_SendUserAgent (parent->GetSendUserAgent ()) {}
~HTTPReqHandler() { Terminate(); }
void Handle () { AsyncSockRead(); } /* overload */
};
@ -315,7 +316,8 @@ namespace proxy {
req.RemoveHeader("X-Forwarded");
req.RemoveHeader("Proxy-"); // Proxy-*
/* replace headers */
req.UpdateHeader("User-Agent", "MYOB/6.66 (AN/ON)");
if (!m_SendUserAgent)
req.UpdateHeader("User-Agent", "MYOB/6.66 (AN/ON)");
/**
* i2pd PR #1816:
@ -751,9 +753,10 @@ namespace proxy {
Done (shared_from_this());
}
HTTPProxy::HTTPProxy(const std::string& name, const std::string& address, uint16_t port, const std::string & outproxy, bool addresshelper, std::shared_ptr<i2p::client::ClientDestination> localDestination):
HTTPProxy::HTTPProxy(const std::string& name, const std::string& address, uint16_t port,
const std::string & outproxy, bool addresshelper, bool senduseragent, std::shared_ptr<i2p::client::ClientDestination> localDestination):
TCPIPAcceptor (address, port, localDestination ? localDestination : i2p::client::context.GetSharedLocalDestination ()),
m_Name (name), m_OutproxyUrl (outproxy), m_Addresshelper (addresshelper)
m_Name (name), m_OutproxyUrl (outproxy), m_Addresshelper (addresshelper), m_SendUserAgent (senduseragent)
{
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2013-2023, The PurpleI2P Project
* Copyright (c) 2013-2024, The PurpleI2P Project
*
* This file is part of Purple i2pd project and licensed under BSD3
*
@ -15,13 +15,15 @@ namespace proxy {
{
public:
HTTPProxy(const std::string& name, const std::string& address, uint16_t port, const std::string & outproxy, bool addresshelper, std::shared_ptr<i2p::client::ClientDestination> localDestination);
HTTPProxy(const std::string& name, const std::string& address, uint16_t port, const std::string & outproxy,
bool addresshelper, bool senduseragent, std::shared_ptr<i2p::client::ClientDestination> localDestination);
HTTPProxy(const std::string& name, const std::string& address, uint16_t port, std::shared_ptr<i2p::client::ClientDestination> localDestination = nullptr) :
HTTPProxy(name, address, port, "", true, localDestination) {} ;
HTTPProxy(name, address, port, "", true, false, localDestination) {} ;
~HTTPProxy() {};
std::string GetOutproxyURL() const { return m_OutproxyUrl; }
bool GetHelperSupport() { return m_Addresshelper; }
bool GetHelperSupport() const { return m_Addresshelper; }
bool GetSendUserAgent () const { return m_SendUserAgent; }
protected:
@ -33,7 +35,7 @@ namespace proxy {
std::string m_Name;
std::string m_OutproxyUrl;
bool m_Addresshelper;
bool m_Addresshelper, m_SendUserAgent;
};
} // http
} // i2p

Loading…
Cancel
Save