Fix authenticated POST/PUT http requests with buffering disabled

If reset is disabled then POST and PUT requests can not be authenticated
as the upload device can not be reset. There shouldn't be any reason
that shouldn't be allowed if the QIODevice given supports resetting.

The disableReset feature of QNonContiguousByteDevice is removed as it
is not used anywhere else, and is redundant when reset can indicate
success or failure.

Task-number: QTBUG-43628
Change-Id: If941a98fd3f797872351c10bdca6aa6745dbefea
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
bb10
Allan Sandfeld Jensen 2015-01-05 14:00:20 +01:00 committed by Allan Sandfeld Jensen
parent de61130bd4
commit 7bd3d4591a
4 changed files with 2 additions and 44 deletions

View File

@ -94,17 +94,7 @@ QT_BEGIN_NAMESPACE
Moves the internal read pointer back to the beginning.
Returns \c false if this was not possible.
\sa atEnd(), disableReset()
\internal
*/
/*!
\fn void QNonContiguousByteDevice::disableReset()
Disable the reset() call, e.g. it will always
do nothing and return false.
\sa reset()
\sa atEnd()
\internal
*/
@ -131,7 +121,7 @@ QT_BEGIN_NAMESPACE
\internal
*/
QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0), resetDisabled(false)
QNonContiguousByteDevice::QNonContiguousByteDevice() : QObject((QObject*)0)
{
}
@ -139,11 +129,6 @@ QNonContiguousByteDevice::~QNonContiguousByteDevice()
{
}
void QNonContiguousByteDevice::disableReset()
{
resetDisabled = true;
}
// FIXME we should scrap this whole implementation and instead change the ByteArrayImpl to be able to cope with sub-arrays?
QNonContiguousByteDeviceBufferImpl::QNonContiguousByteDeviceBufferImpl(QBuffer *b) : QNonContiguousByteDevice()
{
@ -176,8 +161,6 @@ bool QNonContiguousByteDeviceBufferImpl::atEnd()
bool QNonContiguousByteDeviceBufferImpl::reset()
{
if (resetDisabled)
return false;
return arrayImpl->reset();
}
@ -224,9 +207,6 @@ bool QNonContiguousByteDeviceByteArrayImpl::atEnd()
bool QNonContiguousByteDeviceByteArrayImpl::reset()
{
if (resetDisabled)
return false;
currentPosition = 0;
return true;
}
@ -275,9 +255,6 @@ bool QNonContiguousByteDeviceRingBufferImpl::atEnd()
bool QNonContiguousByteDeviceRingBufferImpl::reset()
{
if (resetDisabled)
return false;
currentPosition = 0;
return true;
}
@ -378,8 +355,6 @@ bool QNonContiguousByteDeviceIoDeviceImpl::atEnd()
bool QNonContiguousByteDeviceIoDeviceImpl::reset()
{
if (resetDisabled)
return false;
bool reset = (initialPosition == 0) ? device->reset() : device->seek(initialPosition);
if (reset) {
eof = false; // assume eof is false, it will be true after a read has been attempted

View File

@ -62,8 +62,6 @@ public:
virtual bool advanceReadPointer(qint64 amount) = 0;
virtual bool atEnd() = 0;
virtual bool reset() = 0;
void disableReset();
bool isResetDisabled() { return resetDisabled; }
virtual qint64 size() = 0;
virtual ~QNonContiguousByteDevice();
@ -72,7 +70,6 @@ protected:
QNonContiguousByteDevice();
bool resetDisabled;
Q_SIGNALS:
void readyRead();
void readProgress(qint64 current, qint64 total);

View File

@ -129,12 +129,6 @@ QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice()
return 0;
}
bool bufferDisallowed =
reply->request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute,
QVariant(false)) == QVariant(true);
if (bufferDisallowed)
uploadByteDevice->disableReset();
// We want signal emissions only for normal asynchronous uploads
if (!isSynchronous())
connect(uploadByteDevice.data(), SIGNAL(readProgress(qint64,qint64)), this, SLOT(emitReplyUploadProgress(qint64,qint64)));

View File

@ -856,8 +856,6 @@ void QNetworkReplyHttpImplPrivate::postRequest()
if (uploadByteDevice) {
QNonContiguousByteDeviceThreadForwardImpl *forwardUploadDevice =
new QNonContiguousByteDeviceThreadForwardImpl(uploadByteDevice->atEnd(), uploadByteDevice->size());
if (uploadByteDevice->isResetDisabled())
forwardUploadDevice->disableReset();
forwardUploadDevice->setParent(delegate); // needed to make sure it is moved on moveToThread()
delegate->httpRequest.setUploadByteDevice(forwardUploadDevice);
@ -1896,12 +1894,6 @@ QNonContiguousByteDevice* QNetworkReplyHttpImplPrivate::createUploadByteDevice()
return 0;
}
bool bufferDisallowed =
request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute,
QVariant(false)) == QVariant(true);
if (bufferDisallowed)
uploadByteDevice->disableReset();
// We want signal emissions only for normal asynchronous uploads
if (!synchronous)
QObject::connect(uploadByteDevice.data(), SIGNAL(readProgress(qint64,qint64)),