6#include "QtCore/qdatetime.h"
7#include "QtCore/qmutex.h"
8#include "QtCore/qrandom.h"
249 d->contentType = contentType;
264 d_func()->parts.append(httpPart);
281 d_func()->contentType = contentType;
291 return d_func()->boundary;
319 checkHeaderCreated();
332 checkHeaderCreated();
337 if (readPointer < headerDataCount) {
338 bytesRead =
qMin(headerDataCount - readPointer, maxSize);
339 const char *headerData = header.
constData();
340 memcpy(
data, headerData + readPointer, bytesRead);
341 readPointer += bytesRead;
344 if (bytesRead < maxSize) {
347 if (dataBytesRead == -1)
349 bytesRead += dataBytesRead;
350 readPointer += dataBytesRead;
352 qint64 contentBytesRead =
qMin(
body.
size() - readPointer + headerDataCount, maxSize - bytesRead);
356 memcpy(
data + bytesRead, contentData + readPointer - headerDataCount, contentBytesRead);
357 bytesRead += contentBytesRead;
358 readPointer += contentBytesRead;
366 checkHeaderCreated();
385void QHttpPartPrivate::checkHeaderCreated()
const
387 if (!headerCreated) {
391 const auto name =
h.nameAt(
i);
396 headerCreated =
true;
425 currentSize += boundaryCount + 6;
458 while (index < multiPart->parts.size() &&
464 while (bytesRead < maxSize && index < multiPart->parts.size()) {
470 if (partIndex < boundaryCount) {
471 qint64 boundaryBytesRead =
qMin(boundaryCount - partIndex, maxSize - bytesRead);
472 memcpy(
data + bytesRead, boundaryData.constData() + partIndex, boundaryBytesRead);
473 bytesRead += boundaryBytesRead;
475 partIndex += boundaryBytesRead;
479 if (bytesRead < maxSize && partIndex >= boundaryCount && partIndex < boundaryCount + multiPart->parts.at(
index).d->size()) {
481 if (dataBytesRead == -1)
483 bytesRead += dataBytesRead;
485 partIndex += dataBytesRead;
490 if (bytesRead == maxSize - 1)
492 memcpy(
data + bytesRead,
"\r\n", 2);
499 if (bytesRead < maxSize && index == multiPart->parts.size()) {
502 qint64 lastBoundaryBytesRead =
qMin(finalBoundary.size() - boundaryIndex, maxSize - bytesRead);
503 memcpy(
data + bytesRead, finalBoundary.constData() + boundaryIndex, lastBoundaryBytesRead);
504 bytesRead += lastBoundaryBytesRead;
517#ifndef QT_NO_DEBUG_STREAM
532 debug.resetFormat().nospace().noquote();
534 debug <<
"QHttpPart(headers = ["
536 <<
"], http headers = ["
541 debug <<
" bodydevice = ["
547 debug <<
" size of body = "
562#include "moc_qhttpmultipart.cpp"
IOBluetoothDevice * device
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
static QByteArray fromRawData(const char *data, qsizetype size)
Constructs a QByteArray that uses the first size bytes of the data array.
virtual bool isSequential() const override
Returns true if this device is sequential; otherwise returns false.
virtual qint64 size() const override
For open random-access devices, this function returns the size of the device.
virtual bool reset() override
Seeks to the start of input for random-access devices.
QList< qint64 > partOffsets
virtual qint64 readData(char *data, qint64 maxSize) override
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
virtual qint64 writeData(const char *data, qint64 maxSize) override
Writes up to maxSize bytes from data to the device.
QHttpMultiPartPrivate * multiPart
The QHttpMultiPart class resembles a MIME multipart message to be sent over HTTP.
~QHttpMultiPart()
Destroys the multipart.
ContentType
List of known content types for a multipart subtype as described in RFC 2046 and others.
void append(const QHttpPart &httpPart)
Appends httpPart to this multipart.
QByteArray boundary() const
returns the boundary.
void setContentType(ContentType contentType)
Sets the content type to contentType.
void setBoundary(const QByteArray &boundary)
Sets the boundary to boundary.
QHttpMultiPart(QObject *parent=nullptr)
Constructs a QHttpMultiPart with content type MixedType and sets parent as the parent object.
void setBody(const QByteArray &newBody)
qint64 readData(char *data, qint64 maxSize)
qint64 bytesAvailable() const
void setBodyDevice(QIODevice *device)
The QHttpPart class holds a body part to be used inside a HTTP multipart MIME message.
bool operator==(const QHttpPart &other) const
Returns true if this object is the same as other (i.e., if they have the same headers and body).
QHttpPart & operator=(QHttpPart &&other) noexcept
void setBodyDevice(QIODevice *device)
Sets the device to read the content from to device.
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value)
Sets the value of the known header header to be value, overriding any previously set headers.
QHttpPart()
Constructs an empty QHttpPart object.
void setBody(const QByteArray &body)
Sets the body of this MIME part to body.
~QHttpPart()
Destroys this QHttpPart.
void setRawHeader(const QByteArray &headerName, const QByteArray &headerValue)
Sets the header headerName to be of value headerValue.
\inmodule QtCore \reentrant
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
bool isOpen() const
Returns true if the device is open; otherwise returns false.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
virtual bool reset()
Seeks to the start of input for random-access devices.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
void append(parameter_type t)
KnownHeaders
List of known header types that QNetworkRequest parses.
static Q_DECL_CONST_FUNCTION QRandomGenerator * global()
\threadsafe
Combined button and popup list for selecting options.
static QString header(const QString &name)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
QDebug operator<<(QDebug debug, const QHttpPart &part)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVariant &value)
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat GLfloat GLfloat h