mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-21 16:49:10 +01:00
* HTTPProxy.cpp : allow "tranparent" proxy (#508)
This commit is contained in:
parent
e4edc59689
commit
66c301c031
1 changed files with 22 additions and 3 deletions
|
@ -192,9 +192,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();
|
||||||
|
|
Loading…
Add table
Reference in a new issue