| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QNETWORKREQUESTFACTORY_H |
| 5 | #define QNETWORKREQUESTFACTORY_H |
| 6 | |
| 7 | #include <QtNetwork/qnetworkrequest.h> |
| 8 | #include <QtNetwork/qhttpheaders.h> |
| 9 | |
| 10 | #include <QtCore/qcompare.h> |
| 11 | #include <QtCore/qshareddata.h> |
| 12 | #include <QtCore/qurlquery.h> |
| 13 | #include <QtCore/qurl.h> |
| 14 | #include <QtCore/qvariant.h> |
| 15 | |
| 16 | #include <chrono> |
| 17 | |
| 18 | QT_BEGIN_NAMESPACE |
| 19 | |
| 20 | class QDebug; |
| 21 | #if QT_CONFIG(ssl) |
| 22 | class QSslConfiguration; |
| 23 | #endif |
| 24 | |
| 25 | class QNetworkRequestFactoryPrivate; |
| 26 | QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QNetworkRequestFactoryPrivate, Q_NETWORK_EXPORT) |
| 27 | |
| 28 | class QNetworkRequestFactory |
| 29 | { |
| 30 | public: |
| 31 | Q_NETWORK_EXPORT QNetworkRequestFactory(); |
| 32 | Q_NETWORK_EXPORT explicit QNetworkRequestFactory(const QUrl &baseUrl); |
| 33 | Q_NETWORK_EXPORT ~QNetworkRequestFactory(); |
| 34 | |
| 35 | Q_NETWORK_EXPORT QNetworkRequestFactory(const QNetworkRequestFactory &other); |
| 36 | QNetworkRequestFactory(QNetworkRequestFactory &&other) noexcept = default; |
| 37 | Q_NETWORK_EXPORT QNetworkRequestFactory &operator=(const QNetworkRequestFactory &other); |
| 38 | |
| 39 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QNetworkRequestFactory) |
| 40 | void swap(QNetworkRequestFactory &other) noexcept { d.swap(other&: other.d); } |
| 41 | |
| 42 | Q_NETWORK_EXPORT QUrl baseUrl() const; |
| 43 | Q_NETWORK_EXPORT void setBaseUrl(const QUrl &url); |
| 44 | |
| 45 | #if QT_CONFIG(ssl) |
| 46 | Q_NETWORK_EXPORT QSslConfiguration sslConfiguration() const; |
| 47 | Q_NETWORK_EXPORT void setSslConfiguration(const QSslConfiguration &configuration); |
| 48 | #endif |
| 49 | |
| 50 | Q_NETWORK_EXPORT QNetworkRequest createRequest() const; |
| 51 | Q_NETWORK_EXPORT QNetworkRequest createRequest(const QUrlQuery &query) const; |
| 52 | Q_NETWORK_EXPORT QNetworkRequest createRequest(const QString &path) const; |
| 53 | Q_NETWORK_EXPORT QNetworkRequest createRequest(const QString &path, const QUrlQuery &query) const; |
| 54 | |
| 55 | Q_NETWORK_EXPORT void setCommonHeaders(const QHttpHeaders &headers); |
| 56 | Q_NETWORK_EXPORT QHttpHeaders commonHeaders() const; |
| 57 | Q_NETWORK_EXPORT void clearCommonHeaders(); |
| 58 | |
| 59 | Q_NETWORK_EXPORT QByteArray bearerToken() const; |
| 60 | Q_NETWORK_EXPORT void setBearerToken(const QByteArray &token); |
| 61 | Q_NETWORK_EXPORT void clearBearerToken(); |
| 62 | |
| 63 | Q_NETWORK_EXPORT QString userName() const; |
| 64 | Q_NETWORK_EXPORT void setUserName(const QString &userName); |
| 65 | Q_NETWORK_EXPORT void clearUserName(); |
| 66 | |
| 67 | Q_NETWORK_EXPORT QString password() const; |
| 68 | Q_NETWORK_EXPORT void setPassword(const QString &password); |
| 69 | Q_NETWORK_EXPORT void clearPassword(); |
| 70 | |
| 71 | Q_NETWORK_EXPORT void setTransferTimeout(std::chrono::milliseconds timeout); |
| 72 | Q_NETWORK_EXPORT std::chrono::milliseconds transferTimeout() const; |
| 73 | |
| 74 | Q_NETWORK_EXPORT QUrlQuery queryParameters() const; |
| 75 | Q_NETWORK_EXPORT void setQueryParameters(const QUrlQuery &query); |
| 76 | Q_NETWORK_EXPORT void clearQueryParameters(); |
| 77 | |
| 78 | Q_NETWORK_EXPORT void setPriority(QNetworkRequest::Priority priority); |
| 79 | Q_NETWORK_EXPORT QNetworkRequest::Priority priority() const; |
| 80 | |
| 81 | Q_NETWORK_EXPORT QVariant attribute(QNetworkRequest::Attribute attribute) const; |
| 82 | Q_NETWORK_EXPORT QVariant attribute(QNetworkRequest::Attribute attribute, |
| 83 | const QVariant &defaultValue) const; |
| 84 | Q_NETWORK_EXPORT void setAttribute(QNetworkRequest::Attribute attribute, const QVariant &value); |
| 85 | Q_NETWORK_EXPORT void clearAttribute(QNetworkRequest::Attribute attribute); |
| 86 | Q_NETWORK_EXPORT void clearAttributes(); |
| 87 | |
| 88 | private: |
| 89 | #ifndef QT_NO_DEBUG_STREAM |
| 90 | friend Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QNetworkRequestFactory &reply); |
| 91 | #endif |
| 92 | |
| 93 | QExplicitlySharedDataPointer<QNetworkRequestFactoryPrivate> d; |
| 94 | }; |
| 95 | |
| 96 | Q_DECLARE_SHARED(QNetworkRequestFactory) |
| 97 | |
| 98 | QT_END_NAMESPACE |
| 99 | |
| 100 | #endif // QNETWORKREQUESTFACTORY_H |
| 101 |
