summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/network/access/qhttpnetworkrequest.cpp14
-rw-r--r--src/network/access/qhttpnetworkrequest_p.h7
-rw-r--r--src/network/access/qnetworkaccessbackend.cpp5
-rw-r--r--src/network/access/qnetworkaccesshttpbackend.cpp9
-rw-r--r--src/network/access/qnetworkaccessmanager.cpp37
-rw-r--r--src/network/access/qnetworkaccessmanager.h2
-rw-r--r--src/network/access/qnetworkrequest.cpp6
-rw-r--r--src/network/access/qnetworkrequest.h1
8 files changed, 75 insertions, 6 deletions
diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp
index 8cdfe6a..645deb8 100644
--- a/src/network/access/qhttpnetworkrequest.cpp
+++ b/src/network/access/qhttpnetworkrequest.cpp
@@ -61,6 +61,7 @@ QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(const QHttpNetworkRequest
uploadByteDevice = other.uploadByteDevice;
autoDecompress = other.autoDecompress;
pipeliningAllowed = other.pipeliningAllowed;
+ customVerb = other.customVerb;
}
QHttpNetworkRequestPrivate::~QHttpNetworkRequestPrivate()
@@ -102,6 +103,9 @@ QByteArray QHttpNetworkRequestPrivate::methodName() const
case QHttpNetworkRequest::Connect:
ba += "CONNECT";
break;
+ case QHttpNetworkRequest::Custom:
+ ba += customVerb;
+ break;
default:
break;
}
@@ -230,6 +234,16 @@ void QHttpNetworkRequest::setOperation(Operation operation)
d->operation = operation;
}
+QByteArray QHttpNetworkRequest::customVerb() const
+{
+ return d->customVerb;
+}
+
+void QHttpNetworkRequest::setCustomVerb(const QByteArray &customVerb)
+{
+ d->customVerb = customVerb;
+}
+
QHttpNetworkRequest::Priority QHttpNetworkRequest::priority() const
{
return d->priority;
diff --git a/src/network/access/qhttpnetworkrequest_p.h b/src/network/access/qhttpnetworkrequest_p.h
index dad118e..1b35a84 100644
--- a/src/network/access/qhttpnetworkrequest_p.h
+++ b/src/network/access/qhttpnetworkrequest_p.h
@@ -72,7 +72,8 @@ public:
Put,
Delete,
Trace,
- Connect
+ Connect,
+ Custom
};
enum Priority {
@@ -103,6 +104,9 @@ public:
Operation operation() const;
void setOperation(Operation operation);
+ QByteArray customVerb() const;
+ void setCustomVerb(const QByteArray &customOperation);
+
Priority priority() const;
void setPriority(Priority priority);
@@ -133,6 +137,7 @@ public:
static QByteArray header(const QHttpNetworkRequest &request, bool throughProxy);
QHttpNetworkRequest::Operation operation;
+ QByteArray customVerb;
QHttpNetworkRequest::Priority priority;
mutable QNonContiguousByteDevice* uploadByteDevice;
bool autoDecompress;
diff --git a/src/network/access/qnetworkaccessbackend.cpp b/src/network/access/qnetworkaccessbackend.cpp
index 8ac64d2..34d576a 100644
--- a/src/network/access/qnetworkaccessbackend.cpp
+++ b/src/network/access/qnetworkaccessbackend.cpp
@@ -120,8 +120,11 @@ QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice()
if (reply->outgoingDataBuffer)
device = QNonContiguousByteDeviceFactory::create(reply->outgoingDataBuffer);
- else
+ else if (reply->outgoingData) {
device = QNonContiguousByteDeviceFactory::create(reply->outgoingData);
+ } else {
+ return 0;
+ }
bool bufferDisallowed =
reply->request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute,
diff --git a/src/network/access/qnetworkaccesshttpbackend.cpp b/src/network/access/qnetworkaccesshttpbackend.cpp
index 8e02723..c8f4e5b 100644
--- a/src/network/access/qnetworkaccesshttpbackend.cpp
+++ b/src/network/access/qnetworkaccesshttpbackend.cpp
@@ -213,6 +213,7 @@ QNetworkAccessHttpBackendFactory::create(QNetworkAccessManager::Operation op,
case QNetworkAccessManager::HeadOperation:
case QNetworkAccessManager::PutOperation:
case QNetworkAccessManager::DeleteOperation:
+ case QNetworkAccessManager::CustomOperation:
break;
default:
@@ -526,6 +527,14 @@ void QNetworkAccessHttpBackend::postRequest()
httpRequest.setOperation(QHttpNetworkRequest::Delete);
break;
+ case QNetworkAccessManager::CustomOperation:
+ invalidateCache(); // for safety reasons, we don't know what the operation does
+ httpRequest.setOperation(QHttpNetworkRequest::Custom);
+ httpRequest.setUploadByteDevice(createUploadByteDevice());
+ httpRequest.setCustomVerb(request().attribute(
+ QNetworkRequest::CustomVerbAttribute).toByteArray());
+ break;
+
default:
break; // can't happen
}
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp
index 0b32533..cc4c977 100644
--- a/src/network/access/qnetworkaccessmanager.cpp
+++ b/src/network/access/qnetworkaccessmanager.cpp
@@ -154,6 +154,9 @@ static void ensureInitialized()
\value DeleteOperation delete contents operation (created with
deleteResource())
+ \value CustomOperation custom operation (created with
+ sendCustomRequest())
+
\omitvalue UnknownOperation
\sa QNetworkReply::operation()
@@ -566,7 +569,7 @@ QNetworkReply *QNetworkAccessManager::head(const QNetworkRequest &request)
The contents as well as associated headers will be downloaded.
- \sa post(), put(), deleteResource()
+ \sa post(), put(), deleteResource(), sendCustomRequest()
*/
QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request)
{
@@ -585,7 +588,7 @@ QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request)
\note Sending a POST request on protocols other than HTTP and
HTTPS is undefined and will probably fail.
- \sa get(), put(), deleteResource()
+ \sa get(), put(), deleteResource(), sendCustomRequest()
*/
QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, QIODevice *data)
{
@@ -626,7 +629,7 @@ QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, const
do not allow. Form upload mechanisms, including that of uploading
files through HTML forms, use the POST mechanism.
- \sa get(), post()
+ \sa get(), post(), deleteResource(), sendCustomRequest()
*/
QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, QIODevice *data)
{
@@ -657,7 +660,7 @@ QNetworkReply *QNetworkAccessManager::put(const QNetworkRequest &request, const
\note This feature is currently available for HTTP only, performing an
HTTP DELETE request.
- \sa get(), post(), put()
+ \sa get(), post(), put(), sendCustomRequest()
*/
QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &request)
{
@@ -665,6 +668,32 @@ QNetworkReply *QNetworkAccessManager::deleteResource(const QNetworkRequest &requ
}
/*!
+ \since 4.7
+
+ Sends a custom request to the server identified by the URL of \a request.
+
+ It is the user's responsibility to send a \a verb to the server that is valid
+ according to the HTTP specification.
+
+ This method provides means to send verbs other than the common ones provided
+ via get() or post() etc., for instance sending an HTTP OPTIONS command.
+
+ If \a data is not empty, the contents of the \a data
+ device will be uploaded to the server; in that case, data must be open for
+ reading and must remain valid until the finished() signal is emitted for this reply.
+
+ \note This feature is currently available for HTTP only.
+
+ \sa get(), post(), put(), deleteResource()
+*/
+QNetworkReply *QNetworkAccessManager::sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data)
+{
+ QNetworkRequest newRequest(request);
+ newRequest.setAttribute(QNetworkRequest::CustomVerbAttribute, verb);
+ return d_func()->postProcess(createRequest(QNetworkAccessManager::CustomOperation, newRequest, data));
+}
+
+/*!
Returns a new QNetworkReply object to handle the operation \a op
and request \a req. The device \a outgoingData is always 0 for Get and
Head requests, but is the value passed to post() and put() in
diff --git a/src/network/access/qnetworkaccessmanager.h b/src/network/access/qnetworkaccessmanager.h
index d2fe527..3a8ba58 100644
--- a/src/network/access/qnetworkaccessmanager.h
+++ b/src/network/access/qnetworkaccessmanager.h
@@ -75,6 +75,7 @@ public:
PutOperation,
PostOperation,
DeleteOperation,
+ CustomOperation,
UnknownOperation = 0
};
@@ -102,6 +103,7 @@ public:
QNetworkReply *put(const QNetworkRequest &request, QIODevice *data);
QNetworkReply *put(const QNetworkRequest &request, const QByteArray &data);
QNetworkReply *deleteResource(const QNetworkRequest &request);
+ QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = 0);
Q_SIGNALS:
#ifndef QT_NO_NETWORKPROXY
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index b8438a2..e563f4e 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -182,6 +182,12 @@ QT_BEGIN_NAMESPACE
Indicates whether the HTTP pipelining was used for receiving
this reply.
+ \value CustomVerbAttribute
+ Requests only, type: QVariant::ByteArray
+ Holds the value for the custom HTTP verb to send (destined for usage
+ of other verbs than GET, POST, PUT and DELETE). This verb is set
+ when calling QNetworkAccessManager::sendCustomRequest().
+
\value User
Special type. Additional information can be passed in
QVariants with types ranging from User to UserMax. The default
diff --git a/src/network/access/qnetworkrequest.h b/src/network/access/qnetworkrequest.h
index bc2d9da..a0ef1a6 100644
--- a/src/network/access/qnetworkrequest.h
+++ b/src/network/access/qnetworkrequest.h
@@ -78,6 +78,7 @@ public:
DoNotBufferUploadDataAttribute,
HttpPipeliningAllowedAttribute,
HttpPipeliningWasUsedAttribute,
+ CustomVerbAttribute,
User = 1000,
UserMax = 32767