Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qhttpmultipart_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QHTTPMULTIPART_P_H
6#define QHTTPMULTIPART_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of the Network Access API. This header file may change from
14// version to version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtNetwork/private/qtnetworkglobal_p.h>
20#include <QtNetwork/qhttpmultipart.h>
21
22#include "QtCore/qshareddata.h"
23#include "qnetworkrequest_p.h" // for deriving QHttpPartPrivate from QNetworkHeadersPrivate
25
26#include "private/qobject_p.h"
27#include <QtCore/qiodevice.h>
28
29#ifndef Q_OS_WASM
31#endif
32
33QT_BEGIN_NAMESPACE
34
35
36class QHttpPartPrivate: public QSharedData, public QNetworkHeadersPrivate
37{
38public:
39 inline QHttpPartPrivate() : bodyDevice(nullptr), headerCreated(false), readPointer(0)
40 {
41 }
42 ~QHttpPartPrivate()
43 {
44 }
45
46
47 QHttpPartPrivate(const QHttpPartPrivate &other)
48 : QSharedData(other), QNetworkHeadersPrivate(other), body(other.body),
49 header(other.header), headerCreated(other.headerCreated), readPointer(other.readPointer)
50 {
51 bodyDevice = other.bodyDevice;
52 }
53
54 inline bool operator==(const QHttpPartPrivate &other) const
55 {
56 return QHttpHeadersHelper::compareStrict(httpHeaders, other.httpHeaders)
57 && body == other.body
58 && bodyDevice == other.bodyDevice
59 && readPointer == other.readPointer;
60 }
61
62 void setBodyDevice(QIODevice *device) {
63 bodyDevice = device;
64 readPointer = 0;
65 }
66 void setBody(const QByteArray &newBody) {
67 body = newBody;
68 readPointer = 0;
69 }
70
71 // QIODevice-style methods called by QHttpMultiPartIODevice (but this class is
72 // not a QIODevice):
73 qint64 bytesAvailable() const;
74 qint64 readData(char *data, qint64 maxSize);
75 qint64 size() const;
76 bool reset();
77
78 QByteArray body;
79 QIODevice *bodyDevice;
80
81private:
82 void checkHeaderCreated() const;
83
84 mutable QByteArray header;
85 mutable bool headerCreated;
86 qint64 readPointer;
87};
88
89
90
91class QHttpMultiPartPrivate;
92
93class Q_AUTOTEST_EXPORT QHttpMultiPartIODevice : public QIODevice
94{
95public:
96 QHttpMultiPartIODevice(QHttpMultiPartPrivate *parentMultiPart) :
97 QIODevice(), multiPart(parentMultiPart), readPointer(0), deviceSize(-1) {
98 }
99
100 ~QHttpMultiPartIODevice() override;
101
102 virtual bool atEnd() const override {
103 return readPointer == size();
104 }
105
106 virtual qint64 bytesAvailable() const override {
107 return size() - readPointer;
108 }
109
110 virtual void close() override {
111 readPointer = 0;
112 partOffsets.clear();
113 deviceSize = -1;
114 QIODevice::close();
115 }
116
117 virtual qint64 bytesToWrite() const override {
118 return 0;
119 }
120
121 virtual qint64 size() const override;
122 virtual bool isSequential() const override;
123 virtual bool reset() override;
124 virtual qint64 readData(char *data, qint64 maxSize) override;
125 virtual qint64 writeData(const char *data, qint64 maxSize) override;
126
127 QHttpMultiPartPrivate *multiPart;
128 qint64 readPointer;
129 mutable QList<qint64> partOffsets;
130 mutable qint64 deviceSize;
131};
132
133
134
135class Q_AUTOTEST_EXPORT QHttpMultiPartPrivate: public QObjectPrivate
136{
137public:
138
139 QHttpMultiPartPrivate();
140 ~QHttpMultiPartPrivate() override;
141
142 static QHttpMultiPartPrivate *get(QHttpMultiPart *message) { return message->d_func(); }
143 static const QHttpMultiPartPrivate *get(const QHttpMultiPart *message)
144 {
145 return message->d_func();
146 }
147
148 QList<QHttpPart> parts;
149 QByteArray boundary;
150 QHttpMultiPart::ContentType contentType;
151 QHttpMultiPartIODevice *device;
152
153};
154
155QT_END_NAMESPACE
156
157
158#endif // QHTTPMULTIPART_P_H
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP.
The QHttpPart class holds a body part to be used inside a HTTP multipart MIME message.
QT_REQUIRE_CONFIG(animation)
QT_REQUIRE_CONFIG(http)