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 | |
23 | class Q_NETWORK_EXPORT QHttpPart |
24 | { |
25 | public: |
26 | QHttpPart(); |
27 | QHttpPart(const QHttpPart &other); |
28 | ~QHttpPart(); |
29 | QHttpPart &operator=(QHttpPart &&other) noexcept { swap(other); return *this; } |
30 | QHttpPart &operator=(const QHttpPart &other); |
31 | |
32 | void swap(QHttpPart &other) noexcept { d.swap(other&: other.d); } |
33 | |
34 | bool operator==(const QHttpPart &other) const; |
35 | inline bool operator!=(const QHttpPart &other) const |
36 | { return !operator==(other); } |
37 | |
38 | void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value); |
39 | void setRawHeader(const QByteArray &headerName, const QByteArray &headerValue); |
40 | |
41 | void setBody(const QByteArray &body); |
42 | void setBodyDevice(QIODevice *device); |
43 | |
44 | private: |
45 | QSharedDataPointer<QHttpPartPrivate> d; |
46 | |
47 | friend class QHttpMultiPartIODevice; |
48 | }; |
49 | |
50 | Q_DECLARE_SHARED(QHttpPart) |
51 | |
52 | class QHttpMultiPartPrivate; |
53 | |
54 | class Q_NETWORK_EXPORT QHttpMultiPart : public QObject |
55 | { |
56 | Q_OBJECT |
57 | |
58 | public: |
59 | |
60 | enum ContentType { |
61 | MixedType, |
62 | RelatedType, |
63 | FormDataType, |
64 | AlternativeType |
65 | }; |
66 | |
67 | explicit QHttpMultiPart(QObject *parent = nullptr); |
68 | explicit QHttpMultiPart(ContentType contentType, QObject *parent = nullptr); |
69 | ~QHttpMultiPart(); |
70 | |
71 | void append(const QHttpPart &httpPart); |
72 | |
73 | void setContentType(ContentType contentType); |
74 | |
75 | QByteArray boundary() const; |
76 | void setBoundary(const QByteArray &boundary); |
77 | |
78 | private: |
79 | Q_DECLARE_PRIVATE(QHttpMultiPart) |
80 | Q_DISABLE_COPY(QHttpMultiPart) |
81 | |
82 | friend class QNetworkAccessManager; |
83 | friend class QNetworkAccessManagerPrivate; |
84 | }; |
85 | |
86 | QT_END_NAMESPACE |
87 | |
88 | #endif // QHTTPMULTIPART_H |
89 |