Fix null jsonObject from newHttpJsonRequest (#388)

* Fix null jsonObject from newHttpJsonRequest 

Refer to #372 for the response case as well
This commit is contained in:
ihmc3jn09hk 2020-03-15 00:11:46 +08:00 committed by GitHub
parent 9ee00da431
commit 2401c6a88a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View File

@ -193,6 +193,7 @@ void doTest(const HttpClientPtr &client,
});
// Post json again
req = HttpRequest::newHttpJsonRequest(json);
assert(req->jsonObject());
req->setMethod(drogon::Post);
req->setPath("/api/v1/apitest/json");
client->sendRequest(req,

View File

@ -29,9 +29,9 @@ void HttpRequestImpl::parseJson() const
auto input = contentView();
if (input.empty())
return;
std::string type = getHeaderBy("content-type");
std::transform(type.begin(), type.end(), type.begin(), tolower);
if (type.find("application/json") != std::string::npos)
if (contentType_ == CT_APPLICATION_JSON ||
getHeaderBy("content-type").find("application/json") !=
std::string::npos)
{
static std::once_flag once;
static Json::CharReaderBuilder builder;
@ -48,6 +48,10 @@ void HttpRequestImpl::parseJson() const
jsonPtr_.reset();
}
}
else
{
jsonPtr_.reset();
}
}
void HttpRequestImpl::parseParameters() const
{
@ -628,4 +632,4 @@ void HttpRequestImpl::reserveBodySize()
.append(fileName);
cacheFilePtr_ = std::make_unique<CacheFile>(tmpfile);
}
}
}