|
|
@ -137,8 +137,24 @@ namespace proxy {
|
|
|
|
void HTTPReqHandler::SanitizeHTTPRequest(i2p::http::HTTPReq & req)
|
|
|
|
void HTTPReqHandler::SanitizeHTTPRequest(i2p::http::HTTPReq & req)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
req.del_header("Referer");
|
|
|
|
req.del_header("Referer");
|
|
|
|
req.add_header("Connection", "close", true);
|
|
|
|
req.del_header("Via");
|
|
|
|
req.add_header("User-Agent", "MYOB/6.66 (AN/ON)", true);
|
|
|
|
req.del_header("Forwarded");
|
|
|
|
|
|
|
|
std::vector<std::string> toErase;
|
|
|
|
|
|
|
|
for (auto it : req.headers) {
|
|
|
|
|
|
|
|
if (it.first.compare(0, 12, "X-Forwarded-")) {
|
|
|
|
|
|
|
|
toErase.push_back(it.first);
|
|
|
|
|
|
|
|
} else if (it.first.compare(0, 6, "Proxy-")) {
|
|
|
|
|
|
|
|
toErase.push_back(it.first);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* allow this header */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto header : toErase) {
|
|
|
|
|
|
|
|
req.headers.erase(header);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* replace headers */
|
|
|
|
|
|
|
|
req.add_header("Connection", "close", true); /* keep-alive conns not supported yet */
|
|
|
|
|
|
|
|
req.add_header("User-Agent", "MYOB/6.66 (AN/ON)", true); /* privacy */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -192,9 +208,28 @@ namespace proxy {
|
|
|
|
|
|
|
|
|
|
|
|
std::string dest_host = url.host;
|
|
|
|
std::string dest_host = url.host;
|
|
|
|
uint16_t dest_port = url.port;
|
|
|
|
uint16_t dest_port = url.port;
|
|
|
|
/* convert proxy-style http req to ordinary one: */
|
|
|
|
/* set proper 'Host' header in upstream request */
|
|
|
|
/* 1) replace Host header, 2) make relative url */
|
|
|
|
auto h = req.headers.find("Host");
|
|
|
|
req.add_header("Host", url.host, true);
|
|
|
|
if (dest_host != "") {
|
|
|
|
|
|
|
|
/* absolute url, replace 'Host' header */
|
|
|
|
|
|
|
|
std::string h = dest_host;
|
|
|
|
|
|
|
|
if (dest_port != 0 && dest_port != 80)
|
|
|
|
|
|
|
|
h += ":" + std::to_string(dest_port);
|
|
|
|
|
|
|
|
req.add_header("Host", h, true);
|
|
|
|
|
|
|
|
} else if (h != req.headers.end()) {
|
|
|
|
|
|
|
|
/* relative url and 'Host' header provided. transparent proxy mode? */
|
|
|
|
|
|
|
|
i2p::http::URL u;
|
|
|
|
|
|
|
|
std::string t = "http://" + h->second;
|
|
|
|
|
|
|
|
u.parse(t);
|
|
|
|
|
|
|
|
dest_host = u.host;
|
|
|
|
|
|
|
|
dest_port = u.port;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/* relative url and missing 'Host' header */
|
|
|
|
|
|
|
|
std::string message = "Can't detect destination host from request";
|
|
|
|
|
|
|
|
HTTPRequestFailed(message.c_str());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make relative url */
|
|
|
|
url.schema = "";
|
|
|
|
url.schema = "";
|
|
|
|
url.host = "";
|
|
|
|
url.host = "";
|
|
|
|
req.uri = url.to_string();
|
|
|
|
req.uri = url.to_string();
|
|
|
@ -224,8 +259,10 @@ namespace proxy {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (HandleRequest(len))
|
|
|
|
if (HandleRequest(len)) {
|
|
|
|
|
|
|
|
m_recv_buf.clear();
|
|
|
|
return; /* request processed */
|
|
|
|
return; /* request processed */
|
|
|
|
|
|
|
|
}
|
|
|
|
AsyncSockRead();
|
|
|
|
AsyncSockRead();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|