1 | // Copyright (C) 2016 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 QHTTPMULTIPART_H |
5 | #define QHTTPMULTIPART_H |
6 | |
7 | #include <QtNetwork/qtnetworkglobal.h> |
8 | #include <QtCore/QSharedDataPointer> |
9 | #include <QtCore/QByteArray> |
10 | #include <QtCore/QIODevice> |
11 | #include <QtNetwork/QNetworkRequest> |
12 | |
13 | #ifndef Q_OS_WASM |
14 | QT_REQUIRE_CONFIG(http); |
15 | #endif |
16 | |
17 | QT_BEGIN_NAMESPACE |
18 | |
19 | |
20 | class QHttpPartPrivate; |
21 | class QHttpMultiPart; |
22 | class QDebug; |
23 | |
24 | class Q_NETWORK_EXPORT QHttpPart |
25 | { |
26 | public: |
27 | QHttpPart(); |
28 | QHttpPart(const QHttpPart &other); |
29 | ~QHttpPart(); |
30 | QHttpPart &operator=(QHttpPart &&other) noexcept { swap(other); return *this; } |
31 | QHttpPart &operator=(const QHttpPart &other); |
32 | |
33 | void swap(QHttpPart &other) noexcept { d.swap(other&: other.d); } |
34 | |
35 | bool operator==(const QHttpPart &other) const; |
36 | inline bool operator!=(const QHttpPart &other) const |
37 | { return !operator==(other); } |
38 | |
39 | void (QNetworkRequest::KnownHeaders , const QVariant &value); |
40 | void (const QByteArray &, const QByteArray &); |
41 | |
42 | void setBody(const QByteArray &body); |
43 | void setBodyDevice(QIODevice *device); |
44 | |
45 | private: |
46 | QSharedDataPointer<QHttpPartPrivate> d; |
47 | |
48 | friend class QHttpMultiPartIODevice; |
49 | #ifndef QT_NO_DEBUG_STREAM |
50 | friend Q_NETWORK_EXPORT QDebug operator<<(QDebug debug, const QHttpPart &httpPart); |
51 | #endif |
52 | }; |
53 | |
54 | Q_DECLARE_SHARED(QHttpPart) |
55 | |
56 | class QHttpMultiPartPrivate; |
57 | |
58 | class Q_NETWORK_EXPORT QHttpMultiPart : public QObject |
59 | { |
60 | Q_OBJECT |
61 | |
62 | public: |
63 | |
64 | enum ContentType { |
65 | MixedType, |
66 | RelatedType, |
67 | FormDataType, |
68 | AlternativeType |
69 | }; |
70 | |
71 | explicit QHttpMultiPart(QObject *parent = nullptr); |
72 | explicit QHttpMultiPart(ContentType contentType, QObject *parent = nullptr); |
73 | ~QHttpMultiPart(); |
74 | |
75 | void append(const QHttpPart &httpPart); |
76 | |
77 | void setContentType(ContentType contentType); |
78 | |
79 | QByteArray boundary() const; |
80 | void setBoundary(const QByteArray &boundary); |
81 | |
82 | private: |
83 | Q_DECLARE_PRIVATE(QHttpMultiPart) |
84 | Q_DISABLE_COPY(QHttpMultiPart) |
85 | |
86 | friend class QNetworkAccessManager; |
87 | friend class QNetworkAccessManagerPrivate; |
88 | }; |
89 | |
90 | QT_END_NAMESPACE |
91 | |
92 | #endif // QHTTPMULTIPART_H |
93 | |