From 2cfb697867a6093f16615239bcb082b57b783d3d Mon Sep 17 00:00:00 2001 From: orignal Date: Fri, 12 Feb 2016 15:42:13 -0500 Subject: [PATCH] strip our Referer and replace User-Agent --- HTTPProxy.cpp | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/HTTPProxy.cpp b/HTTPProxy.cpp index c417d904..f0166a4a 100644 --- a/HTTPProxy.cpp +++ b/HTTPProxy.cpp @@ -176,28 +176,39 @@ namespace proxy m_request.push_back('\r'); m_request.push_back('\n'); m_request.append("Connection: close\r\n"); - m_request.append(reinterpret_cast(http_buff),len); + // TODO: temporary shortcut. Must be implemented properly + uint8_t * eol = nullptr; + bool isEndOfHeader = false; + while (!isEndOfHeader && len && (eol = (uint8_t *)memchr (http_buff, '\r', len))) + { + if (eol) + { + *eol = 0; eol++; + if (strncmp ((const char *)http_buff, "Referer", 7)) // strip out referer + { + if (!strncmp ((const char *)http_buff, "User-Agent", 10)) // replace UserAgent + m_request.append("User-Agent: MYOB/6.66 (AN/ON)"); + else + m_request.append ((const char *)http_buff); + m_request.append ("\r\n"); + } + isEndOfHeader = !http_buff[0]; + auto l = eol - http_buff; + http_buff = eol; + len -= l; + if (len > 0) // \r + { + http_buff++; + len--; + } + } + } + m_request.append(reinterpret_cast(http_buff),len); return true; } bool HTTPProxyHandler::HandleData(uint8_t *http_buff, std::size_t len) { - // TODO: we should srtrip 'Referer' better, because it might be inside message body - /*assert(len); // This should always be called with a least a byte left to parse - - // remove "Referer" from http requst - http_buff[len] = 0; - auto start = strstr((char *)http_buff, "\nReferer:"); - if (start) - { - auto end = strchr (start + 1, '\n'); - if (end) - { - strncpy(start, end, (char *)(http_buff + len) - end); - len -= (end - start); - } - }*/ - while (len > 0) { //TODO: fallback to finding HOst: header if needed