Browse Source

rewrite for efficiency

pull/1295/head
l-n-s 6 years ago
parent
commit
016ae3b9e9
  1. 6
      libi2pd_client/HTTPProxy.cpp
  2. 8
      libi2pd_client/I2PTunnel.cpp

6
libi2pd_client/HTTPProxy.cpp

@ -219,9 +219,11 @@ namespace proxy {
/* replace headers */ /* replace headers */
req.UpdateHeader("User-Agent", "MYOB/6.66 (AN/ON)"); req.UpdateHeader("User-Agent", "MYOB/6.66 (AN/ON)");
/* add headers */ /* add headers */
/* close connection, if not Connection: (U|u)pgrade (for websocket) */
auto h = req.GetHeader ("Connection"); auto h = req.GetHeader ("Connection");
if (h.find("upgrade") == std::string::npos && h.find("Upgrade") == std::string::npos) auto x = h.find("pgrade");
req.UpdateHeader("Connection", "close"); /* close everything, except websocket */ if (!(x != std::string::npos && std::tolower(h[x - 1]) == 'u'))
req.UpdateHeader("Connection", "close");
} }
/** /**

8
libi2pd_client/I2PTunnel.cpp

@ -256,10 +256,12 @@ namespace client
{ {
if (!m_ConnectionSent && !line.compare(0, 10, "Connection")) if (!m_ConnectionSent && !line.compare(0, 10, "Connection"))
{ {
if (line.find("upgrade") == std::string::npos && line.find("Upgrade") == std::string::npos) /* close connection, if not Connection: (U|u)pgrade (for websocket) */
m_OutHeader << "Connection: close\r\n"; /* close everything, except websocket */ auto x = line.find("pgrade");
else if (x != std::string::npos && std::tolower(line[x - 1]) == 'u')
m_OutHeader << line << "\r\n"; m_OutHeader << line << "\r\n";
else
m_OutHeader << "Connection: close\r\n";
m_ConnectionSent = true; m_ConnectionSent = true;
} }

Loading…
Cancel
Save