don't trust the server since it doesn't always give proper mime...

This commit is contained in:
DarthArgus
2019-03-04 01:33:42 +00:00
parent e0b9b98028
commit 638ed7b15a
3 changed files with 9 additions and 6 deletions

View File

@@ -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) {

View File

@@ -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();

View File

@@ -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);