From 768fa69b6bb8177bff055c71edc5fde2274d42e5 Mon Sep 17 00:00:00 2001 From: kervala Date: Sun, 8 May 2016 13:39:17 +0200 Subject: [PATCH] Fixed: Use correct formatted HTTP 1.1 query, previous one was blocked by some security software (a big thanks to Vojtech Vobr from AVG Technologies for his investigation to help us to fix this issue) --- .../common/src/game_share/http_client.cpp | 54 ++++++++++++++++--- 1 file changed, 46 insertions(+), 8 deletions(-) diff --git a/code/ryzom/common/src/game_share/http_client.cpp b/code/ryzom/common/src/game_share/http_client.cpp index c48087037..78fd02797 100644 --- a/code/ryzom/common/src/game_share/http_client.cpp +++ b/code/ryzom/common/src/game_share/http_client.cpp @@ -98,27 +98,56 @@ bool CHttpClient::send(const std::string& buffer, bool verbose) // *************************************************************************** bool CHttpClient::sendRequest(const std::string& methodWB, const std::string &url, const std::string &cookieName, const std::string &cookieValue, const std::string& postParams, bool verbose) { - // Remove the host from the URL - string path; + std::string path, host; + + // Remove the protocol from the URL if (url.substr(0, 7) == "http://") path = url.substr(7); else path = url; - path = path.substr(path.find( "/" )); + + std::string::size_type pos = path.find("/"); + + // Remove the host from the URL + if (pos != std::string::npos) + { + host = path.substr(0, pos); + path = path.substr(pos); + } + else + { + host = path; + path.clear(); + } + + // build HTTP request + std::string request; + request += methodWB + " " + path + " HTTP/1.1\r\n"; + request += "Host: " + host + "\r\n"; // Send if (cookieName.empty() && postParams.empty()) { - return send(methodWB + path + "\r\n", verbose); + request += "\r\n"; + + return send(request, verbose); } else { - string cookieStr, postStr; if (!cookieName.empty()) - cookieStr = "Cookie: " + cookieName + "=" + cookieValue + "\r\n"; + request += "Cookie: " + cookieName + "=" + cookieValue + "\r\n"; + if (!postParams.empty()) - postStr = "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: " + toString(postParams.size()) + "\r\n\r\n" + postParams; - return send(methodWB + path + " HTTP/1.0\r\n" + cookieStr + postStr + "\r\n", verbose); + { + request += "Content-Type: application/x-www-form-urlencoded\r\n"; + request += "Content-Length: " + toString(postParams.size()) + "\r\n"; + request += "\r\n"; + request += postParams; + } + + request += "\r\n"; + + return send(request, verbose); } } @@ -179,6 +208,15 @@ bool CHttpClient::receive(string &res, bool verbose) } } //nlinfo("all received '%s'", res.c_str()); + + // only keep content (delimited by two \r\n) and discard server headers + std::string::size_type pos = res.find("\r\n\r\n"); + + if (pos != std::string::npos) + { + res = res.substr(pos + 4); + } + return true; }