aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2020-03-30 19:12:40 +0200
committerKitsune Ral <Kitsune-Ral@users.sf.net>2020-03-30 19:57:16 +0200
commitd38516e4e123474876e4fc7f850fe321ec5ccb54 (patch)
tree2d9bcd4d6a8d6a4a445c6fe467cf61936d6a0edd /lib
parentecc31fc7a615faa516a03c07ebd96d0d2494c315 (diff)
downloadlibquotient-d38516e4e123474876e4fc7f850fe321ec5ccb54.tar.gz
libquotient-d38516e4e123474876e4fc7f850fe321ec5ccb54.zip
BaseJob: check the connection even harder
Diffstat (limited to 'lib')
-rw-r--r--lib/jobs/basejob.cpp39
1 files changed, 23 insertions, 16 deletions
diff --git a/lib/jobs/basejob.cpp b/lib/jobs/basejob.cpp
index 8b63f7e8..65668521 100644
--- a/lib/jobs/basejob.cpp
+++ b/lib/jobs/basejob.cpp
@@ -234,6 +234,7 @@ void BaseJob::Private::sendRequest()
req.setMaximumRedirectsAllowed(10);
req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);
req.setAttribute(QNetworkRequest::HTTP2AllowedAttribute, true);
+ Q_ASSERT(req.url().isValid());
for (auto it = requestHeaders.cbegin(); it != requestHeaders.cend(); ++it)
req.setRawHeader(it.key(), it.value());
@@ -261,25 +262,31 @@ void BaseJob::beforeAbandon(QNetworkReply*) {}
void BaseJob::initiate(ConnectionData* connData, bool inBackground)
{
- Q_ASSERT(connData != nullptr);
+ if (connData && connData->baseUrl().isValid()) {
+ d->inBackground = inBackground;
+ d->connection = connData;
+ doPrepare();
- d->inBackground = inBackground;
- d->connection = connData;
- doPrepare();
-
- if ((d->verb == HttpVerb::Post || d->verb == HttpVerb::Put)
- && d->requestData.source() && !d->requestData.source()->isReadable()) {
- setStatus(FileError, "Request data not ready");
- }
- Q_ASSERT(status().code != Pending); // doPrepare() must NOT set this
- if (status().code == Unprepared) {
- d->connection->submit(this);
- } else {
- qDebug(d->logCat).noquote()
+ if ((d->verb == HttpVerb::Post || d->verb == HttpVerb::Put)
+ && d->requestData.source() && !d->requestData.source()->isReadable()) {
+ setStatus(FileError, "Request data not ready");
+ }
+ Q_ASSERT(status().code != Pending); // doPrepare() must NOT set this
+ if (status().code == Unprepared) {
+ d->connection->submit(this);
+ return;
+ }
+ qCWarning(d->logCat).noquote()
<< "Request failed preparation and won't be sent:"
<< d->dumpRequest();
- QTimer::singleShot(0, this, &BaseJob::finishJob);
+ } else {
+ qCCritical(d->logCat)
+ << "Developers, ensure the Connection is valid before using it";
+ Q_ASSERT(false);
+ setStatus(IncorrectRequestError, tr("Invalid server connection"));
}
+ // The status is no good, finalise
+ QTimer::singleShot(0, this, &BaseJob::finishJob);
}
void BaseJob::sendRequest()
@@ -338,7 +345,7 @@ bool checkContentType(const QByteArray& type, const QByteArrayList& patterns)
// ignore possible appendixes of the content type
const auto ctype = type.split(';').front();
- for (const auto& pattern : patterns) {
+ for (const auto& pattern: patterns) {
if (pattern.startsWith('*') || ctype == pattern) // Fast lane
return true;