1/*
2 SPDX-FileCopyrightText: 2016 Dan Leinir Turthra Jensen <admin@leinir.dk>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#ifndef HTTPJOB_H
8#define HTTPJOB_H
9
10#include "jobbase.h"
11
12#include <QNetworkReply>
13#include <QUrl>
14
15#include <memory>
16
17namespace KNSCore
18{
19class HttpJobPrivate;
20class HTTPJob : public KJob
21{
22 Q_OBJECT
23public:
24 explicit HTTPJob(const QUrl &source, LoadType loadType = Reload, JobFlags flags = DefaultFlags, QObject *parent = nullptr);
25 explicit HTTPJob(QObject *parent = nullptr);
26 ~HTTPJob() override;
27
28 Q_SLOT void start() override;
29
30 static HTTPJob *get(const QUrl &source, LoadType loadType = Reload, JobFlags flags = DefaultFlags, QObject *parent = nullptr);
31
32Q_SIGNALS:
33 /**
34 * Data from the worker has arrived.
35 * @param job the job that emitted this signal
36 * @param data data received from the worker.
37 *
38 * End of data (EOD) has been reached if data.size() == 0, however, you
39 * should not be certain of data.size() == 0 ever happening (e.g. in case
40 * of an error), so you should rely on result() instead.
41 */
42 void data(KJob *job, const QByteArray &data);
43
44 /**
45 * Fired in case there is a http error reported
46 * In some instances this is useful information for our users, and we want to make sure we report this centrally
47 * @param status The HTTP status code (fired in cases where it is perceived by QNetworkReply as an error)
48 * @param rawHeaders The raw HTTP headers for the errored-out network request
49 */
50 void httpError(int status, QList<QNetworkReply::RawHeaderPair> rawHeaders);
51
52protected Q_SLOTS:
53 void handleWorkerData(const QByteArray &data);
54 void handleWorkerCompleted();
55 void handleWorkerError(const QString &error);
56
57private:
58 const std::unique_ptr<HttpJobPrivate> d;
59};
60
61}
62
63#endif // HTTPJOB_H
64

source code of knewstuff/src/core/jobs/httpjob.h