diff options
author | Sona Kurazyan <sona.kurazyan@qt.io> | 2019-03-06 17:14:56 +0100 |
---|---|---|
committer | Sona Kurazyan <sona.kurazyan@qt.io> | 2019-03-11 16:53:31 +0000 |
commit | 872ab757fd2ab19f2b004b38a176ac7700de9926 (patch) | |
tree | 2d10b2afa9d5f82069ec1ae136caa7afd9e838cf /src | |
parent | d9d26033bb3945cf69654b505f85f9786e42eade (diff) |
Hide APIs for specifying the request method
Since the request method is set anyway when sending a request
(get, put, post, etc.), allowing users to specify the request
method is fatuous (it will be overridden anyway when sending
the request).
Change-Id: Ibf079bd513f145c791d5d703aa5685bfe66dda7d
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/coap/qcoapclient.cpp | 30 | ||||
-rw-r--r-- | src/coap/qcoaprequest.cpp | 21 | ||||
-rw-r--r-- | src/coap/qcoaprequest.h | 11 |
3 files changed, 23 insertions, 39 deletions
diff --git a/src/coap/qcoapclient.cpp b/src/coap/qcoapclient.cpp index 09e171c..6787092 100644 --- a/src/coap/qcoapclient.cpp +++ b/src/coap/qcoapclient.cpp @@ -228,12 +228,6 @@ QCoapReply *QCoapClient::get(const QCoapRequest &request) { Q_D(QCoapClient); - if (request.method() != QtCoap::Invalid - && request.method() != QtCoap::Get) { - qWarning("QCoapClient::get: Overriding method specified on request:" - "using 'Get' instead."); - } - QCoapRequest copyRequest(request, QtCoap::Get); copyRequest.adjustUrl(d->connection->isSecure()); @@ -263,12 +257,6 @@ QCoapReply *QCoapClient::put(const QCoapRequest &request, const QByteArray &data { Q_D(QCoapClient); - if (request.method() != QtCoap::Invalid - && request.method() != QtCoap::Put) { - qWarning("QCoapClient::put: Overriding method specified on request:" - "using 'Put' instead."); - } - QCoapRequest copyRequest(request, QtCoap::Put); copyRequest.setPayload(data); copyRequest.adjustUrl(d->connection->isSecure()); @@ -315,12 +303,6 @@ QCoapReply *QCoapClient::post(const QCoapRequest &request, const QByteArray &dat { Q_D(QCoapClient); - if (request.method() != QtCoap::Invalid - && request.method() != QtCoap::Post) { - qWarning("QCoapClient::post: Overriding method specified on request:" - "using 'Post' instead."); - } - QCoapRequest copyRequest(request, QtCoap::Post); copyRequest.setPayload(data); copyRequest.adjustUrl(d->connection->isSecure()); @@ -370,12 +352,6 @@ QCoapReply *QCoapClient::deleteResource(const QCoapRequest &request) { Q_D(QCoapClient); - if (request.method() != QtCoap::Invalid - && request.method() != QtCoap::Delete) { - qWarning("QCoapClient::deleteResource: Overriding method specified on request:" - "using 'Delete' instead."); - } - QCoapRequest copyRequest(request, QtCoap::Delete); copyRequest.adjustUrl(d->connection->isSecure()); @@ -473,12 +449,6 @@ QCoapDiscoveryReply *QCoapClient::discover(const QUrl &url, const QString &disco */ QCoapReply *QCoapClient::observe(const QCoapRequest &request) { - if (request.method() != QtCoap::Invalid - && request.method() != QtCoap::Get) { - qWarning("QCoapClient::observe: Overriding method specified on request:" - "using 'Get' instead."); - } - QCoapRequest copyRequest(request, QtCoap::Get); copyRequest.enableObserve(); diff --git a/src/coap/qcoaprequest.cpp b/src/coap/qcoaprequest.cpp index f3fdca8..c1ab691 100644 --- a/src/coap/qcoaprequest.cpp +++ b/src/coap/qcoaprequest.cpp @@ -125,15 +125,24 @@ QCoapRequest::QCoapRequest(const char *url, MessageType type) : } /*! - Constructs a copy of the \a other QCoapRequest. Optionally allows to - overwrite the QtCoap::Method of the request with the \a method - argument. + Constructs a copy of the \a other QCoapRequest. */ -QCoapRequest::QCoapRequest(const QCoapRequest &other, QtCoap::Method method) : +QCoapRequest::QCoapRequest(const QCoapRequest &other) : //! No private data sharing, as QCoapRequestPrivate!=QCoapMessagePrivate //! and the d_ptr is a QSharedDataPointer<QCoapMessagePrivate> QCoapMessage(*new QCoapRequestPrivate(*other.d_func())) { +} + +/*! + \internal + + Constructs a copy of the \a other QCoapRequest and sets the request + method to \a method. +*/ +QCoapRequest::QCoapRequest(const QCoapRequest &other, QtCoap::Method method) : + QCoapRequest(other) +{ if (method != QtCoap::Invalid) setMethod(method); } @@ -170,8 +179,6 @@ QUrl QCoapRequest::proxyUrl() const /*! Returns the method of the request. - - \sa setMethod() */ QtCoap::Method QCoapRequest::method() const { @@ -215,6 +222,8 @@ void QCoapRequest::setProxyUrl(const QUrl &proxyUrl) } /*! + \internal + Sets the method of the request to the given \a method. \sa method() diff --git a/src/coap/qcoaprequest.h b/src/coap/qcoaprequest.h index 7d6c7a5..600a635 100644 --- a/src/coap/qcoaprequest.h +++ b/src/coap/qcoaprequest.h @@ -50,8 +50,7 @@ public: const QUrl &proxyUrl = QUrl()); explicit QCoapRequest(const char* url, MessageType type = NonConfirmable); - QCoapRequest(const QCoapRequest &other, - QtCoap::Method method = QtCoap::Invalid); + QCoapRequest(const QCoapRequest &other); ~QCoapRequest(); QCoapRequest &operator=(const QCoapRequest &other); @@ -62,7 +61,6 @@ public: bool isObserve() const; void setUrl(const QUrl &url); void setProxyUrl(const QUrl &proxyUrl); - void setMethod(QtCoap::Method method); void enableObserve(); void adjustUrl(bool secure); @@ -70,11 +68,18 @@ public: static bool isUrlValid(const QUrl &url); static QUrl adjustedUrl(const QUrl &url, bool secure); +protected: + QCoapRequest(const QCoapRequest &other, QtCoap::Method method); + + void setMethod(QtCoap::Method method); + private: // Q_DECLARE_PRIVATE equivalent for shared data pointers inline QCoapRequestPrivate* d_func(); const QCoapRequestPrivate* d_func() const { return reinterpret_cast<const QCoapRequestPrivate*>(d_ptr.constData()); } + + friend class QCoapClient; }; QT_END_NAMESPACE |