service/AuthenticatedRequest.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <QNetworkAccessManager> | ||
| 4 | #include <QNetworkRequest> | ||
| 5 | #include <QPointer> | ||
| 6 | #include <functional> | ||
| 7 | |||
| 8 | // One explicit redirect boundary for subscription credentials and push tokens. | ||
| 9 | class AuthenticatedRequest : public QObject { | ||
| 10 | public: | ||
| 11 | enum class Outcome { Ok, Unauthorized, RedirectedToForeignHost, InsecureRedirect, | ||
| 12 | TooManyRedirects, Limit, Network }; | ||
| 13 | enum class ForeignRedirect { FollowWithoutCredentials, Refuse }; | ||
| 14 | struct Hop { | ||
| 15 | QUrl url; | ||
| 16 | Outcome outcome = Outcome::Ok; | ||
| 17 | bool attachAuthorization = false; | ||
| 18 | }; | ||
| 19 | struct Result { | ||
| 20 | Outcome outcome = Outcome::Network; | ||
| 21 | QByteArray body; | ||
| 22 | QUrl url; | ||
| 23 | int status = 0; | ||
| 24 | QString detail; | ||
| 25 | bool leftOrigin = false; | ||
| 26 | }; | ||
| 27 | using Callback = std::function<void(Result)>; | ||
| 28 | |||
| 29 | static Hop nextHop(const QUrl &origin, const QUrl ¤t, const QUrl &location, int hops); | ||
| 30 | static AuthenticatedRequest *start(QObject *owner, QNetworkAccessManager *manager, | ||
| 31 | QNetworkRequest request, QByteArray authorization, QByteArray body, bool post, | ||
| 32 | ForeignRedirect policy, Callback callback); | ||
| 33 | ~AuthenticatedRequest() override; | ||
| 34 | void cancel(); | ||
| 35 | private: | ||
| 36 |
2/2✓ Branch 5 → 6 taken 14 times.
✓ Branch 6 → 7 taken 14 times.
|
14 | explicit AuthenticatedRequest(QObject *parent) : QObject(parent) {} |
| 37 | void send(const QUrl &url, bool attachAuthorization); | ||
| 38 | void finished(); | ||
| 39 | void complete(Result result); | ||
| 40 | QPointer<QNetworkAccessManager> m_manager; | ||
| 41 | QPointer<QNetworkReply> m_reply; | ||
| 42 | QNetworkRequest m_request; | ||
| 43 | QUrl m_origin; | ||
| 44 | QByteArray m_authorization; | ||
| 45 | QByteArray m_body; | ||
| 46 | bool m_post = false; | ||
| 47 | bool m_leftOrigin = false; | ||
| 48 | int m_hops = 0; | ||
| 49 | ForeignRedirect m_policy = ForeignRedirect::Refuse; | ||
| 50 | Callback m_callback; | ||
| 51 | }; | ||
| 52 |