Changeset View
Changeset View
Standalone View
Standalone View
src/core/job.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
57 | FileLogger *FileLogger::self() | 57 | FileLogger *FileLogger::self() | ||
58 | { | 58 | { | ||
59 | if (!sInstance) { | 59 | if (!sInstance) { | ||
60 | sInstance = new FileLogger(); | 60 | sInstance = new FileLogger(); | ||
61 | } | 61 | } | ||
62 | return sInstance; | 62 | return sInstance; | ||
63 | } | 63 | } | ||
64 | 64 | | |||
65 | void FileLogger::logRequest(const KGAPI2::Request &request) | 65 | void FileLogger::logRequest(const QNetworkRequest &request, const QByteArray &rawData) | ||
66 | { | 66 | { | ||
67 | if (!mFile) { | 67 | if (!mFile) { | ||
68 | return; | 68 | return; | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | QTextStream stream(mFile.data()); | 71 | QTextStream stream(mFile.data()); | ||
72 | stream << "C: " << request.request.url().toDisplayString() << "\n"; | 72 | stream << "C: " << request.url().toDisplayString() << "\n"; | ||
73 | stream << " Content-type: " << request.contentType << "\n"; | 73 | const auto headers = request.rawHeaderList(); | ||
74 | const auto headers = request.request.rawHeaderList(); | | |||
75 | for (const auto &header : headers) { | 74 | for (const auto &header : headers) { | ||
76 | stream << " " << header << ": " << request.request.rawHeader(header) << "\n\n"; | 75 | stream << " " << header << ": " << request.rawHeader(header) << "\n"; | ||
77 | } | 76 | } | ||
78 | stream << " " << request.rawData << "\n\n"; | 77 | stream << " " << rawData << "\n\n"; | ||
79 | mFile->flush(); | 78 | mFile->flush(); | ||
80 | } | 79 | } | ||
81 | 80 | | |||
82 | void FileLogger::logReply(const QNetworkReply *reply, const QByteArray &rawData) | 81 | void FileLogger::logReply(const QNetworkReply *reply, const QByteArray &rawData) | ||
83 | { | 82 | { | ||
84 | if (!mFile) { | 83 | if (!mFile) { | ||
85 | return; | 84 | return; | ||
86 | } | 85 | } | ||
87 | 86 | | |||
88 | QTextStream stream(mFile.data()); | 87 | QTextStream stream(mFile.data()); | ||
89 | stream << "S: " << reply->url().toDisplayString() << "\n"; | 88 | stream << "S: " << reply->url().toDisplayString() << "\n"; | ||
90 | const auto headers = reply->rawHeaderList(); | 89 | const auto headers = reply->rawHeaderList(); | ||
91 | for (const auto &header : headers) { | 90 | for (const auto &header : headers) { | ||
92 | stream << " " << header << ": " << reply->rawHeader(header) << "\n\n"; | 91 | stream << " " << header << ": " << reply->rawHeader(header) << "\n"; | ||
93 | } | 92 | } | ||
94 | stream << " " << rawData; | 93 | stream << " " << rawData << "\n\n"; | ||
95 | mFile->flush(); | 94 | mFile->flush(); | ||
96 | } | 95 | } | ||
97 | 96 | | |||
98 | 97 | | |||
99 | 98 | | |||
100 | Job::Private::Private(Job *parent): | 99 | Job::Private::Private(Job *parent): | ||
101 | isRunning(false), | 100 | isRunning(false), | ||
102 | error(KGAPI2::NoError), | 101 | error(KGAPI2::NoError), | ||
▲ Show 20 Lines • Show All 214 Lines • ▼ Show 20 Line(s) | 315 | { | |||
317 | if (requestQueue.isEmpty()) { | 316 | if (requestQueue.isEmpty()) { | ||
318 | dispatchTimer->stop(); | 317 | dispatchTimer->stop(); | ||
319 | return; | 318 | return; | ||
320 | } | 319 | } | ||
321 | 320 | | |||
322 | const Request r = requestQueue.dequeue(); | 321 | const Request r = requestQueue.dequeue(); | ||
323 | currentRequest = r; | 322 | currentRequest = r; | ||
324 | 323 | | |||
324 | QNetworkRequest authorizedRequest = r.request; | ||||
325 | if (account) { | ||||
326 | authorizedRequest.setRawHeader("Authorization", "Bearer " + account->accessToken().toLatin1()); | ||||
327 | } | ||||
325 | qCDebug(KGAPIDebug) << q << "Dispatching request to" << r.request.url(); | 328 | qCDebug(KGAPIDebug) << q << "Dispatching request to" << r.request.url(); | ||
326 | FileLogger::self()->logRequest(r); | 329 | FileLogger::self()->logRequest(authorizedRequest, r.rawData); | ||
327 | 330 | | |||
328 | q->dispatchRequest(accessManager, r.request, r.rawData, r.contentType); | 331 | q->dispatchRequest(accessManager, authorizedRequest, r.rawData, r.contentType); | ||
329 | 332 | | |||
330 | if (requestQueue.isEmpty()) { | 333 | if (requestQueue.isEmpty()) { | ||
331 | dispatchTimer->stop(); | 334 | dispatchTimer->stop(); | ||
332 | } | 335 | } | ||
333 | } | 336 | } | ||
334 | 337 | | |||
335 | /************************* PUBLIC **********************/ | 338 | /************************* PUBLIC **********************/ | ||
336 | 339 | | |||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |