From e000929c0b06752703056b890ff0b5a4deae1c6a Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Sat, 3 Feb 2018 19:13:09 +0900 Subject: BaseJob::makeRequestUrl A static method that constructs a request URL for this job and the passed set of parameters. --- jobs/basejob.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'jobs/basejob.cpp') 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"), -- cgit v1.2.3