aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-03 19:13:09 +0900
committerKitsune Ral <Kitsune-Ral@users.sf.net>2018-02-03 19:15:29 +0900
commite000929c0b06752703056b890ff0b5a4deae1c6a (patch)
treeae1cd7bb972f0c41438612a5fce3291b6b04ab72
parentffb8233d1b6ac54e37391e1949697ba8f6828f47 (diff)
downloadlibquotient-e000929c0b06752703056b890ff0b5a4deae1c6a.tar.gz
libquotient-e000929c0b06752703056b890ff0b5a4deae1c6a.zip
BaseJob::makeRequestUrl
A static method that constructs a request URL for this job and the passed set of parameters.
-rw-r--r--jobs/basejob.cpp21
-rw-r--r--jobs/basejob.h8
2 files changed, 21 insertions, 8 deletions
diff --git a/jobs/basejob.cpp b/jobs/basejob.cpp
index 2d0d8b1b..c35a7711 100644
--- a/jobs/basejob.cpp
+++ b/jobs/basejob.cpp
@@ -179,17 +179,22 @@ void BaseJob::setExpectedContentTypes(const QByteArrayList& contentTypes)
d->expectedContentTypes = contentTypes;
}
-void BaseJob::Private::sendRequest()
+QUrl BaseJob::makeRequestUrl(QUrl baseUrl,
+ const QString& path, const QUrlQuery& query)
{
- QUrl url = connection->baseUrl();
- QString path = url.path();
- if (!path.endsWith('/') && !apiEndpoint.startsWith('/'))
- path.push_back('/');
+ auto pathBase = baseUrl.path();
+ if (!pathBase.endsWith('/') && !path.startsWith('/'))
+ pathBase.push_back('/');
- url.setPath( path + apiEndpoint );
- url.setQuery(requestQuery);
+ baseUrl.setPath( pathBase + path );
+ baseUrl.setQuery(query);
+ return baseUrl;
+}
- QNetworkRequest req {url};
+void BaseJob::Private::sendRequest()
+{
+ QNetworkRequest req
+ { makeRequestUrl(connection->baseUrl(), apiEndpoint, requestQuery) };
if (!requestHeaders.contains("Content-Type"))
req.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
req.setRawHeader(QByteArray("Authorization"),
diff --git a/jobs/basejob.h b/jobs/basejob.h
index e9e108c6..c03c914f 100644
--- a/jobs/basejob.h
+++ b/jobs/basejob.h
@@ -212,6 +212,14 @@ namespace QMatrixClient
void addExpectedContentType(const QByteArray& contentType);
void setExpectedContentTypes(const QByteArrayList& contentTypes);
+ /** Construct a URL out of baseUrl, path and query
+ * The function automatically adds '/' between baseUrl's path and
+ * \p path if necessary. The query component of \p baseUrl
+ * is ignored.
+ */
+ static QUrl makeRequestUrl(QUrl baseUrl, const QString& path,
+ const QUrlQuery& query = {});
+
virtual void beforeStart(const ConnectionData* connData);
virtual void afterStart(const ConnectionData* connData,
QNetworkReply* reply);