more work

This commit is contained in:
Cameron Gutman
2018-04-28 22:14:27 -07:00
parent a38bef6bc4
commit a5d50cd4f0
8 changed files with 322 additions and 97 deletions

View File

@@ -8,8 +8,9 @@
#define REQUEST_TIMEOUT_MS 5000
NvHTTP::NvHTTP(QString address) :
m_Address(address)
NvHTTP::NvHTTP(QString address, IdentityManager im) :
m_Address(address),
m_Im(im)
{
m_BaseUrlHttp.setScheme("http");
m_BaseUrlHttps.setScheme("https");
@@ -69,6 +70,8 @@ NvHTTP::getServerVersionQuad(QString serverInfo)
{
ret.append(parts.at(i).toInt());
}
return ret;
}
int
@@ -104,7 +107,7 @@ NvHTTP::getServerInfo()
// Throws if the request failed
verifyResponseStatus(serverInfo);
}
catch (GfeHttpResponseException& e)
catch (const GfeHttpResponseException& e)
{
if (e.getStatusCode() == 401)
{
@@ -115,6 +118,11 @@ NvHTTP::getServerInfo()
true);
verifyResponseStatus(serverInfo);
}
else
{
// Rethrow real errors
throw e;
}
}
return serverInfo;
@@ -185,10 +193,10 @@ NvHTTP::openConnection(QUrl baseUrl,
{
// Build a URL for the request
QUrl url(baseUrl);
url.setPath(command +
"?uniqueid=" + "0" +
"&uuid=" + QUuid::createUuid().toString() +
((arguments != nullptr) ? (arguments + "&") : ""));
url.setPath("/" + command);
url.setQuery("uniqueid=" + m_Im.getUniqueId() +
"&uuid=" + QUuid::createUuid().toRfc4122().toHex() +
((arguments != nullptr) ? ("&" + arguments) : ""));
QNetworkReply* reply = m_Nam.get(QNetworkRequest(url));
@@ -215,8 +223,8 @@ NvHTTP::openConnection(QUrl baseUrl,
// Handle error
if (reply->error() != QNetworkReply::NoError)
{
qDebug() << command << " request for failed with error " << reply->error();
GfeHttpResponseException* exception = new GfeHttpResponseException(reply->error(), reply->errorString());
qDebug() << command << " request failed with error " << reply->error();
GfeHttpResponseException exception(reply->error(), reply->errorString());
delete reply;
throw exception;
}