Skip to content
This repository was archived by the owner on May 30, 2023. It is now read-only.
This repository was archived by the owner on May 30, 2023. It is now read-only.

HTTP PATCH requests do not send body #11384

Closed

Description

@sgsabbage

Much in the same vein as issues #11367 and #10873 , sending an AJAX PATCH request does not send the body, and instead just sends a blank body. PATCH requests are documented in RFC5789, and are supported by all the browsers I've tested in.

Arguably, it also exists in RFC2068, but I'm aware that that does label it an 'experimental' feature.

Activity

  1. le0pard commented on Jul 19, 2013

    @le0pard

    +1 - the same problem.

  2. paultyng commented on Jul 23, 2013

    @paultyng

    Can confirm this problem as well. Rails 4 now supports PATCH out of the box for resources so have been using it but cannot use PhantomJS to test and have had to revert to chrome driver.

  3. danielwestendorf commented on Jul 23, 2013

    @danielwestendorf

    +1 same problem

  4. hanssgo commented on Aug 7, 2013

    @hanssgo

    +1. Just ran into this problem as well

  5. paultyng commented on Aug 7, 2013

    @paultyng
  6. papilip commented on Aug 13, 2013

    @papilip

    +1 we have the same problem

  7. frobean commented on Aug 22, 2013

    @frobean

    I ran into this yesterday and didn't have time to wait on an official fix (if one is even planned) so I went in and added sufficient support to get it working for my purposes running on linux. If anyone else would like to patch & build, you can use the following patch. It should apply cleanly to 1.9.1

    diff --git src/networkaccessmanager.cpp src/networkaccessmanager.cpp
    index fbe8af1..b04463b 100644
    --- src/networkaccessmanager.cpp
    +++ src/networkaccessmanager.cpp
    @@ -59,6 +59,9 @@ static const char *toString(QNetworkAccessManager::Operation op)
         case QNetworkAccessManager::PostOperation:
             str = "POST";
             break;
    +    case QNetworkAccessManager::PatchOperation:
    +        str = "PATCH";
    +        break;
         case QNetworkAccessManager::DeleteOperation:
             str = "DELETE";
             break;
    diff --git src/qt/src/3rdparty/webkit/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp src/qt/src/3rdparty/webkit/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
    index 3cf6439..0921225 100644
    --- src/qt/src/3rdparty/webkit/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
    +++ src/qt/src/3rdparty/webkit/Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
    @@ -368,6 +368,8 @@ String QNetworkReplyHandler::httpMethod() const
             return "POST";
         case QNetworkAccessManager::PutOperation:
             return "PUT";
    +    case QNetworkAccessManager::PatchOperation:
    +        return "PATCH";
         case QNetworkAccessManager::DeleteOperation:
             return "DELETE";
         case QNetworkAccessManager::CustomOperation:
    @@ -395,6 +397,8 @@ QNetworkReplyHandler::QNetworkReplyHandler(ResourceHandle* handle, LoadType load
             m_method = QNetworkAccessManager::PostOperation;
         else if (r.httpMethod() == "PUT")
             m_method = QNetworkAccessManager::PutOperation;
    +    else if (r.httpMethod() == "PATCH")
    +        m_method = QNetworkAccessManager::PatchOperation;
         else if (r.httpMethod() == "DELETE")
             m_method = QNetworkAccessManager::DeleteOperation;
         else
    @@ -623,7 +627,7 @@ QNetworkReply* QNetworkReplyHandler::sendNetworkRequest(QNetworkAccessManager* m
             && (!url.toLocalFile().isEmpty() || url.scheme() == QLatin1String("data")))
             m_method = QNetworkAccessManager::GetOperation;
    
    -    if (m_method != QNetworkAccessManager::PostOperation && m_method != QNetworkAccessManager::PutOperation) {
    +    if (m_method != QNetworkAccessManager::PostOperation && m_method != QNetworkAccessManager::PutOperation && m_method != QNetworkAccessManager::PatchRequest) {
             // clearing Contents-length and Contents-type of the requests that do not have contents.
             m_request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant());
             m_request.setHeader(QNetworkRequest::ContentLengthHeader, QVariant());
    @@ -641,6 +645,15 @@ QNetworkReply* QNetworkReplyHandler::sendNetworkRequest(QNetworkAccessManager* m
                 postDevice->setParent(result);
                 return result;
             }
    +        case QNetworkAccessManager::PatchOperation: {
    +            FormDataIODevice* patchDevice = new FormDataIODevice(request.httpBody());
    +            // We may be uploading files so prevent QNR from buffering data
    +            m_request.setHeader(QNetworkRequest::ContentLengthHeader, patchDevice->getFormDataSize());
    +            m_request.setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, QVariant(true));
    +            QNetworkReply* result = manager->patch(m_request, patchDevice);
    +            patchDevice->setParent(result);
    +            return result;
    +        }
             case QNetworkAccessManager::HeadOperation:
                 return manager->head(m_request);
             case QNetworkAccessManager::PutOperation: {
    diff --git src/qt/src/3rdparty/webkit/Source/WebKit/qt/Api/qwebframe.cpp src/qt/src/3rdparty/webkit/Source/WebKit/qt/Api/qwebframe.cpp
    index 04453b6..c517734 100644
    --- src/qt/src/3rdparty/webkit/Source/WebKit/qt/Api/qwebframe.cpp
    +++ src/qt/src/3rdparty/webkit/Source/WebKit/qt/Api/qwebframe.cpp
    @@ -908,6 +908,9 @@ void QWebFrame::load(const QNetworkRequest &req,
             case QNetworkAccessManager::PostOperation:
                 request.setHTTPMethod("POST");
                 break;
    +        case QNetworkAccessManager::PatchOperation:
    +            request.setHTTPMethod("PATCH");
    +            break;
             case QNetworkAccessManager::DeleteOperation:
                 request.setHTTPMethod("DELETE");
                 break;
    diff --git src/qt/src/network/access/qhttp.cpp src/qt/src/network/access/qhttp.cpp
    index dea23f9..984133d 100644
    --- src/qt/src/network/access/qhttp.cpp
    +++ src/qt/src/network/access/qhttp.cpp
    @@ -2254,6 +2254,27 @@ int QHttp::post(const QString &path, const QByteArray &data, QIODevice *to)
         return d->addRequest(new QHttpPGHRequest(header, new QByteArray(data), to));
     }
    
    +int QHttp::patch(const QString &path, QIODevice *data, QIODevice *to )
    +{
    +    Q_D(QHttp);
    +    QHttpRequestHeader header(QLatin1String("PATCH"), path);
    +    header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
    +    return d->addRequest(new QHttpPGHRequest(header, data, to));
    +}
    +
    +/*!
    +    \overload
    +
    +    \a data is used as the content data of the HTTP request.
    +*/
    +int QHttp::patch(const QString &path, const QByteArray &data, QIODevice *to)
    +{
    +    Q_D(QHttp);
    +    QHttpRequestHeader header(QLatin1String("PATCH"), path);
    +    header.setValue(QLatin1String("Connection"), QLatin1String("Keep-Alive"));
    +    return d->addRequest(new QHttpPGHRequest(header, new QByteArray(data), to));
    +}
    +
     /*!
         Sends a header request for \a path to the server set by setHost()
         or as specified in the constructor.
    diff --git src/qt/src/network/access/qhttp.h src/qt/src/network/access/qhttp.h
    index 9700e6e..1590806 100644
    --- src/qt/src/network/access/qhttp.h
    +++ src/qt/src/network/access/qhttp.h
    @@ -223,6 +223,8 @@ public:
         int get(const QString &path, QIODevice *to=0);
         int post(const QString &path, QIODevice *data, QIODevice *to=0 );
         int post(const QString &path, const QByteArray &data, QIODevice *to=0);
    +    int patch(const QString &path, QIODevice *data, QIODevice *to=0 );
    +    int patch(const QString &path, const QByteArray &data, QIODevice *to=0);
         int head(const QString &path);
         int request(const QHttpRequestHeader &header, QIODevice *device=0, QIODevice *to=0);
         int request(const QHttpRequestHeader &header, const QByteArray &data, QIODevice *to=0);
    diff --git src/qt/src/network/access/qhttpnetworkrequest.cpp src/qt/src/network/access/qhttpnetworkrequest.cpp
    index 617541f..78a2d82 100644
    --- src/qt/src/network/access/qhttpnetworkrequest.cpp
    +++ src/qt/src/network/access/qhttpnetworkrequest.cpp
    @@ -90,6 +90,9 @@ QByteArray QHttpNetworkRequestPrivate::methodName() const
         case QHttpNetworkRequest::Post:
             return "POST";
             break;
    +    case QHttpNetworkRequest::Patch:
    +        return "PATCH";
    +        break;
         case QHttpNetworkRequest::Options:
             return "OPTIONS";
             break;
    diff --git src/qt/src/network/access/qhttpnetworkrequest_p.h src/qt/src/network/access/qhttpnetworkrequest_p.h
    index 3b98342..4b6d654 100644
    --- src/qt/src/network/access/qhttpnetworkrequest_p.h
    +++ src/qt/src/network/access/qhttpnetworkrequest_p.h
    @@ -69,6 +69,7 @@ public:
             Get,
             Head,
             Post,
    +        Patch,
             Put,
             Delete,
             Trace,
    diff --git src/qt/src/network/access/qnetworkaccesshttpbackend.cpp src/qt/src/network/access/qnetworkaccesshttpbackend.cpp
    index 1d048ee..ffd6b32 100644
    --- src/qt/src/network/access/qnetworkaccesshttpbackend.cpp
    +++ src/qt/src/network/access/qnetworkaccesshttpbackend.cpp
    @@ -171,6 +171,7 @@ QNetworkAccessHttpBackendFactory::create(QNetworkAccessManager::Operation op,
         switch (op) {
         case QNetworkAccessManager::GetOperation:
         case QNetworkAccessManager::PostOperation:
    +    case QNetworkAccessManager::PatchOperation:
         case QNetworkAccessManager::HeadOperation:
         case QNetworkAccessManager::PutOperation:
         case QNetworkAccessManager::DeleteOperation:
    @@ -453,6 +454,12 @@ void QNetworkAccessHttpBackend::postRequest()
             createUploadByteDevice();
             break;
    
    +    case QNetworkAccessManager::PatchOperation:
    +        invalidateCache();
    +        httpRequest.setOperation(QHttpNetworkRequest::Patch);
    +        createUploadByteDevice();
    +        break;
    +
         case QNetworkAccessManager::PutOperation:
             invalidateCache();
             httpRequest.setOperation(QHttpNetworkRequest::Put);
    diff --git src/qt/src/network/access/qnetworkaccessmanager.cpp src/qt/src/network/access/qnetworkaccessmanager.cpp
    index 84b1b4b..6cc63d2 100644
    --- src/qt/src/network/access/qnetworkaccessmanager.cpp
    +++ src/qt/src/network/access/qnetworkaccessmanager.cpp
    @@ -715,6 +715,56 @@ QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, const
         return reply;
     }
    
    +QNetworkReply *QNetworkAccessManager::patch(const QNetworkRequest &request, QHttpMultiPart *multiPart)
    +{
    +    QNetworkRequest newRequest = d_func()->prepareMultipart(request, multiPart);
    +    QIODevice *device = multiPart->d_func()->device;
    +    QNetworkReply *reply = patch(newRequest, device);
    +    return reply;
    +}
    +
    +/*!
    + Uploads the contents of \a data to the destination \a request and
    + returnes a new QNetworkReply object that will be open for reply.
    + 
    + \a data must be opened for reading when this function is called
    + and must remain valid until the finished() signal is emitted for
    + this reply.
    + 
    + Whether anything will be available for reading from the returned
    + object is protocol dependent. For HTTP, the server may send a
    + small HTML page indicating the upload was successful (or not).
    + Other protocols will probably have content in their replies.
    + 
    + \note For HTTP, this request will send a PUT request, which most servers
    + do not allow. Form upload mechanisms, including that of uploading
    + files through HTML forms, use the POST mechanism.
    + 
    + \sa get(), post(), deleteResource(), sendCustomRequest()
    + */
    +QNetworkReply *QNetworkAccessManager::patch(const QNetworkRequest &request, QIODevice *data)
    +{
    +    return d_func()->postProcess(createRequest(QNetworkAccessManager::PatchOperation, request, data));
    +}
    +
    +/*!
    + \overload
    + 
    + Sends the contents of the \a data byte array to the destination
    + specified by \a request.
    + */
    +QNetworkReply *QNetworkAccessManager::patch(const QNetworkRequest &request, const QByteArray &data)
    +{
    +    QBuffer *buffer = new QBuffer;
    +    buffer->setData(data);
    +    buffer->open(QIODevice::ReadOnly);
    +    
    +    QNetworkReply *reply = patch(request, buffer);
    +    buffer->setParent(reply);
    +    return reply;
    +}
    +
    +
     /*!
         \since 4.6
    
    diff --git src/qt/src/network/access/qnetworkaccessmanager.h src/qt/src/network/access/qnetworkaccessmanager.h
    index 26a28e1..52b8452 100644
    --- src/qt/src/network/access/qnetworkaccessmanager.h
    +++ src/qt/src/network/access/qnetworkaccessmanager.h
    @@ -84,6 +84,7 @@ public:
             PutOperation,
             PostOperation,
             DeleteOperation,
    +        PatchOperation,
             CustomOperation,
    
             UnknownOperation = 0
    @@ -121,6 +122,9 @@ public:
         QNetworkReply *put(const QNetworkRequest &request, QIODevice *data);
         QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data);
         QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart);
    +    QNetworkReply *patch(const QNetworkRequest &request, QIODevice *data);
    +    QNetworkReply *patch(const QNetworkRequest &request, const QByteArray &data);
    +    QNetworkReply *patch(const QNetworkRequest &request, QHttpMultiPart *multiPart);
         QNetworkReply *deleteResource(const QNetworkRequest &request);
         QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = 0);
    
    diff --git src/webpage.cpp src/webpage.cpp
    index c76a4b8..a56b46a 100644
    --- src/webpage.cpp
    +++ src/webpage.cpp
    @@ -817,6 +817,8 @@ void WebPage::openUrl(const QString &address, const QVariant &op, const QVariant
             networkOp = QNetworkAccessManager::PutOperation;
         else if (operation == "post")
             networkOp = QNetworkAccessManager::PostOperation;
    +    else if (operation == "patch")
    +        networkOp = QNetworkAccessManager::PatchOperation;
         else if (operation == "delete")
             networkOp = QNetworkAccessManager::DeleteOperation;
  8. dominicbarnes commented on Aug 27, 2013

    @dominicbarnes

    +1

  9. paultyng commented on Aug 28, 2013

    @paultyng

    I think that Phantom may be already using a custom Qt build, but not sure, so not sure if we should actually customize Qt per that patch or add some other implementation for this.

  10. mdaverde commented on Sep 10, 2013

    @mdaverde

    +1

  11. sasata299 commented on Sep 13, 2013

    @sasata299

    +1

  12. StevePotter commented on Sep 23, 2013

    @StevePotter

    +1

  13. butzopower commented on Sep 27, 2013

    @butzopower

    +1, we banged our head on this for a while

  14. obweger commented on Oct 8, 2013

    @obweger

    +1 - also, patch requests have content type application/octet-stream, regardless of what you set in code (using jQuery's "ajax" method).

  15. 44 remaining items

  16. added a commit that references this issue on Apr 10, 2015
  17. dholdren commented on May 7, 2015

    @dholdren

    this is fixed in 2.0, shouldn't this be closed?

  18. sfontana commented on Jul 14, 2015

    @sfontana

    I don't think this was fixed in 2.0, sadface.

  19. 3rd-Eden commented on Aug 31, 2015

    @3rd-Eden

    How is this not resolved yet?! There are patch files and countless of people needing this.

  20. Sinewyk commented on Aug 31, 2015

    @Sinewyk

    It is fixed in 2.0, did a quick test case to confirm it. It's just that 2.x cannot take off until binary are available for all platforms so, wait or help =)

  21. reidcooper commented on Jun 21, 2016

    @reidcooper

    I am having this issue currently. PhantomJS 2.1.X. My BackboneJS PATCH requests are sending empty body requests to my rails api.

  22. andremleblanc commented on Jun 22, 2016

    @andremleblanc

    I had this problem too, I just switched to PUT for now; but, it would be nice to have this.

  23. dholdren commented on Jun 22, 2016

    @dholdren

    This bug is back in 2.1 ?

  24. reidcooper commented on Jun 22, 2016

    @reidcooper

    On my local machine, I am properly able to perform a PATCH request with the body that I want, however I am using Semaphore for my CI. My same tests do not perform the PATCH requests. I am curious on what could not be sending them.

  25. dholdren commented on Jun 23, 2016

    @dholdren

    @reidcooper semaphore defaults to PhantomJS 1.9.8 https://semaphoreci.com/docs/phantomjs.html

  26. reidcooper commented on Jun 23, 2016

    @reidcooper

    @dholdren that seems to have fixed my problem, thanks a lot. However, I did not think about this before because in my Gemfile.lock, I do have version 2.1 of phantomjs?

  27. kannans commented on Aug 3, 2016

    @kannans

    👍 PUT method working thanks @here

  28. stale commented on Dec 28, 2019

    @stale

    Due to our very limited maintenance capacity (see #14541 for more details), we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed. In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions