From 638ed7b15a814a9d30a06c04c50104305375ff73 Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Mon, 4 Mar 2019 01:33:42 +0000 Subject: [PATCH] don't trust the server since it doesn't always give proper mime... --- .../LoginServer/src/shared/ClientConnection.cpp | 2 +- external/3rd/library/webAPI/webAPI.cpp | 11 +++++++---- external/3rd/library/webAPI/webAPI.h | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp index 4b432ef8..4111669b 100755 --- a/engine/server/application/LoginServer/src/shared/ClientConnection.cpp +++ b/engine/server/application/LoginServer/src/shared/ClientConnection.cpp @@ -186,7 +186,7 @@ void ClientConnection::validateClient(const std::string &id, const std::string & bool done = api.setData(postData); if (done) { - done = api.submit(1,1,1); + done = api.submit(1,1); } if (done) { diff --git a/external/3rd/library/webAPI/webAPI.cpp b/external/3rd/library/webAPI/webAPI.cpp index 78f64853..98d853be 100644 --- a/external/3rd/library/webAPI/webAPI.cpp +++ b/external/3rd/library/webAPI/webAPI.cpp @@ -84,7 +84,7 @@ bool webAPI::submit(const int &reqType, const int &getPost, const int &respType) } } - if (fetch(getPost, respType) && !(sResponse.empty())) { + if (fetch(getPost, reqType, respType) && !(sResponse.empty())) { return true; } @@ -93,7 +93,7 @@ bool webAPI::submit(const int &reqType, const int &getPost, const int &respType) return false; } -bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for string +bool webAPI::fetch(const int &getPost, const int &mimeType, const int &respMimeType) // 0 for json 1 for string { bool fetchStatus = false; @@ -107,12 +107,15 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for // set the content type if (mimeType == DTYPE::JSON) { - slist = curl_slist_append(slist, "Accept: application/json"); slist = curl_slist_append(slist, "Content-Type: application/json"); } else { slist = curl_slist_append(slist, "Content-Type: application/x-www-form-urlencoded"); } + if (respMimeType == DTYPE::JSON) { + slist = curl_slist_append(slist, "Accept: application/json"); + } + slist = curl_slist_append(slist, "charsets: utf-8"); curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent.c_str()); @@ -156,7 +159,7 @@ bool webAPI::fetch(const int &getPost, const int &mimeType) // 0 for json 1 for if (statusCode == 200 && !(readBuffer.empty())) // check it all out and parse { sResponse = readBuffer; - if (conType == "application/json") { + if (conType == "application/json" || respMimeType == 0) { fetchStatus = processJSON(); } else { responseData.clear(); diff --git a/external/3rd/library/webAPI/webAPI.h b/external/3rd/library/webAPI/webAPI.h index 501c18cb..ccc43219 100644 --- a/external/3rd/library/webAPI/webAPI.h +++ b/external/3rd/library/webAPI/webAPI.h @@ -104,7 +104,7 @@ namespace StellaBellum { std::string uri; // fetcher - returns raw response direct from remote - bool fetch(const int &getPost = HTTP::POST, const int &mimeType = DTYPE::JSON); + bool fetch(const int &getPost = HTTP::POST, const int &mimeType = DTYPE::JSON, const int &respMimeType = DTYPE::JSON); // cURL writeback callback static size_t writeCallback(void *contents, size_t size, size_t nmemb, void *userp);