Fix#5856 - Add support for PATCH (#5875)

* Changing QBuffer to use a QByteArray solves the issue for me since there is no real use-case for using a QBuffer.

Documentation of QT5 states:

QBuffer::QBuffer(QByteArray *byteArray, QObject *parent = Q_NULLPTR)

Constructs a QBuffer that uses the QByteArray pointed to by byteArray as its internal buffer, and with the given parent. The caller is responsible for ensuring that byteArray remains valid until the QBuffer is destroyed, or until setBuffer() is called to change the buffer. QBuffer doesn't take ownership of the QByteArray.

Since the variable “request_content” is allocated on the stack, this is clearly wrong and a bug. The construction of QBuffer is designed this way so that whenever you write to the buffer, it is also written to the byte array that it is pointing to

* Add a retro-compatible solution based on QNetworkAccessManager SourceCode

* update samples
This commit is contained in:
sabras75 2017-06-19 17:08:32 +02:00 committed by wing328
parent 981ad60050
commit 24c55d1f0e
3 changed files with 33 additions and 6 deletions

View File

@ -4,6 +4,7 @@
#include <QUrl>
#include <QFileInfo>
#include <QBuffer>
#include <QtGlobal>
{{#cppNamespaceDeclarations}}
@ -283,8 +284,16 @@ void HttpRequestWorker::execute(HttpRequestInput *input) {
manager->deleteResource(request);
}
else {
QBuffer buff(&request_content);
manager->sendCustomRequest(request, input->http_method.toLatin1(), &buff);
#if (QT_VERSION >= 0x050800)
manager->sendCustomRequest(request, input->http_method.toLatin1(), request_content);
#else
QBuffer *buffer = new QBuffer;
buffer->setData(request_content);
buffer->open(QIODevice::ReadOnly);
QNetworkReply* reply = manager->sendCustomRequest(request, input->http_method.toLatin1(), buffer);
buffer->setParent(reply);
#endif
}
}

View File

@ -15,6 +15,7 @@
#include <QUrl>
#include <QFileInfo>
#include <QBuffer>
#include <QtGlobal>
namespace Swagger {
@ -292,8 +293,16 @@ void HttpRequestWorker::execute(HttpRequestInput *input) {
manager->deleteResource(request);
}
else {
QBuffer buff(&request_content);
manager->sendCustomRequest(request, input->http_method.toLatin1(), &buff);
#if (QT_VERSION >= 0x050800)
manager->sendCustomRequest(request, input->http_method.toLatin1(), request_content);
#else
QBuffer *buffer = new QBuffer;
buffer->setData(request_content);
buffer->open(QIODevice::ReadOnly);
QNetworkReply* reply = manager->sendCustomRequest(request, input->http_method.toLatin1(), buffer);
buffer->setParent(reply);
#endif
}
}

View File

@ -15,6 +15,7 @@
#include <QUrl>
#include <QFileInfo>
#include <QBuffer>
#include <QtGlobal>
namespace Swagger {
@ -292,8 +293,16 @@ void HttpRequestWorker::execute(HttpRequestInput *input) {
manager->deleteResource(request);
}
else {
QBuffer buff(&request_content);
manager->sendCustomRequest(request, input->http_method.toLatin1(), &buff);
#if (QT_VERSION >= 0x050800)
manager->sendCustomRequest(request, input->http_method.toLatin1(), request_content);
#else
QBuffer *buffer = new QBuffer;
buffer->setData(request_content);
buffer->open(QIODevice::ReadOnly);
QNetworkReply* reply = manager->sendCustomRequest(request, input->http_method.toLatin1(), buffer);
buffer->setParent(reply);
#endif
}
}