QHttp2Connection: add sendDATA(QByteArray)
Inside QtNetwork itself we are using byte-devices, but outside users need to send byte-arrays. The solution then is to wrap it in a QBuffer, but the QBuffer then needs to be allocated and deleted for each transmission. Change-Id: I1e5870b11450f0bd2b68fedb01d1653de115ffda Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Mate Barany <mate.barany@qt.io>
This commit is contained in:
parent
b950ec2525
commit
46b84b0b69
@ -234,6 +234,25 @@ bool QHttp2Stream::sendRST_STREAM(quint32 errorCode)
|
||||
return frameWriter.write(*connection->getSocket());
|
||||
}
|
||||
|
||||
/*!
|
||||
Sends a DATA frame with the bytes obtained from \a payload.
|
||||
|
||||
This function will send as many DATA frames as needed to send all the data
|
||||
from \a payload. If \a endStream is \c true, the END_STREAM flag will be
|
||||
set.
|
||||
*/
|
||||
void QHttp2Stream::sendDATA(const QByteArray &payload, bool endStream)
|
||||
{
|
||||
Q_ASSERT(!m_uploadByteDevice);
|
||||
if (m_state != State::Open && m_state != State::HalfClosedRemote)
|
||||
return;
|
||||
|
||||
auto *byteDevice = QNonContiguousByteDeviceFactory::create(payload);
|
||||
connect(this, &QHttp2Stream::uploadFinished, byteDevice, &QObject::deleteLater);
|
||||
byteDevice->setParent(this);
|
||||
sendDATA(byteDevice, endStream);
|
||||
}
|
||||
|
||||
/*!
|
||||
Sends a DATA frame with the bytes obtained from \a device.
|
||||
|
||||
|
@ -132,6 +132,7 @@ public Q_SLOTS:
|
||||
bool sendRST_STREAM(quint32 errorCode);
|
||||
bool sendHEADERS(const HPack::HttpHeader &headers, bool endStream,
|
||||
quint8 priority = DefaultPriority);
|
||||
void sendDATA(const QByteArray &payload, bool endStream);
|
||||
void sendDATA(QIODevice *device, bool endStream);
|
||||
void sendDATA(QNonContiguousByteDevice *device, bool endStream);
|
||||
void sendWINDOW_UPDATE(quint32 delta);
|
||||
|
@ -352,11 +352,8 @@ void tst_QHttp2Connection::WINDOW_UPDATE()
|
||||
// we can check the headers now immediately
|
||||
QCOMPARE(serverStream->receivedHeaders(), expectedRequestHeaders);
|
||||
|
||||
QBuffer *buffer = new QBuffer(clientStream);
|
||||
QByteArray uploadedData = "Hello World"_ba.repeated(1000);
|
||||
buffer->setData(uploadedData);
|
||||
buffer->open(QIODevice::ReadWrite);
|
||||
clientStream->sendDATA(buffer, true);
|
||||
clientStream->sendDATA(uploadedData, true);
|
||||
|
||||
bool streamEnd = false;
|
||||
QByteArray serverReceivedData;
|
||||
@ -374,10 +371,7 @@ void tst_QHttp2Connection::WINDOW_UPDATE()
|
||||
|
||||
const HPack::HttpHeader ExpectedResponseHeaders{ { ":status", "200" } };
|
||||
serverStream->sendHEADERS(ExpectedResponseHeaders, false);
|
||||
QBuffer *serverBuffer = new QBuffer(serverStream);
|
||||
serverBuffer->setData(uploadedData);
|
||||
serverBuffer->open(QIODevice::ReadWrite);
|
||||
serverStream->sendDATA(serverBuffer, true);
|
||||
serverStream->sendDATA(uploadedData, true);
|
||||
|
||||
QVERIFY(clientHeaderReceivedSpy.wait());
|
||||
const HPack::HttpHeader
|
||||
|
Loading…
x
Reference in New Issue
Block a user