From: Stijn Last Date: Thu, 21 Nov 2017 16:02:54 +0100 Subject: [PATCH] QtWebkit post with empty data does not work QNetworkReplyHandler posts with empty data are broken since this commit in IODevice https://github.com/qt/qtbase/commit/06632928afbd44b13d333f390bc50403e63f87a4 Notice that this line in the code was removed: return readSoFar ? readSoFar : qint64(-1); Making QIODevice::read to return 0 (used to be -1) when QIODevice::readData returns 0 When posting empty data FormDataIODevice::m_formElements does contain 1 element, but element.m_data.size()==0 In that case FormDataIODevice::readData returns 0 when called the first time, -1 when called a second time This is the logic in QNetworkAccessManager::post: (implemented in qnetworkreplyhttpimpl.cpp) QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); ... // read data into our buffer forever { bytesToBuffer = outgoingData->bytesAvailable(); // unknown? just try 2 kB, this also ensures we always try to read the EOF if (bytesToBuffer <= 0) bytesToBuffer = 2*1024; char *dst = outgoingDataBuffer->reserve(bytesToBuffer); bytesBuffered = outgoingData->read(dst, bytesToBuffer); if (bytesBuffered == -1) { // EOF has been reached. outgoingDataBuffer->chop(bytesToBuffer); _q_bufferOutgoingDataFinished(); break; } else if (bytesBuffered == 0) { // nothing read right now, just wait until we get called again outgoingDataBuffer->chop(bytesToBuffer); break; } else { // don't break, try to read() again outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered); } } A read returning 0 will break the while loop, waiting for the readyRead signal to continue FormDataIODevice will never emit the readyRead signal since there's no more data to read. Documentation of QIODevice states: 0 is returned when no more data is available for reading. If there are no bytes to be read and there can never be more bytes available (examples include socket closed, pipe closed, sub-process finished), this function returns -1. Making FormDataIODevice::readData to return -1 in the first call resolves the problem diff --git a/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp b/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp index e07bc76..8adc037 100644 --- a/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp +++ b/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp @@ -199,6 +199,10 @@ qint64 FormDataIODevice::readData(char* destination, qint64 size) } } + if (size > 0 && copied==0 && m_formElements.isEmpty()) { + return -1; + } + return copied; }