path: root/src/network
diff options
authorAllan Sandfeld Jensen <>2014-11-12 16:58:15 +0100
committerAllan Sandfeld Jensen <>2014-11-19 09:59:10 +0100
commitccd4da392c366dd4f7f71fa3b8aeddde1b3bc169 (patch)
treed104190a6b79ce065bb1855edc0ba991340ca960 /src/network
parent9990e47f047925fce978ebda849bd7ae88608003 (diff)
Do not force a content-type on POST request with no content
While a POST request with no body may be a pointless thing it does happen on many websites. Currently this causes QtNetwork to print a warning to the console and set an invalid content-type. This patch allows the content-type to be absent when content is. Task-number: QTBUG-42479 Change-Id: Ia84c89147d2469a9421b9694d062c797987b3194 Reviewed-by: Jocelyn Turcotte <> Reviewed-by: Thiago Macieira <>
Diffstat (limited to 'src/network')
1 files changed, 1 insertions, 1 deletions
diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp
index f50a79b061..66f093e490 100644
--- a/src/network/access/qhttpnetworkrequest.cpp
+++ b/src/network/access/qhttpnetworkrequest.cpp
@@ -151,7 +151,7 @@ QByteArray QHttpNetworkRequestPrivate::header(const QHttpNetworkRequest &request
if (request.d->operation == QHttpNetworkRequest::Post) {
// add content type, if not set in the request
- if (request.headerField("content-type").isEmpty()) {
+ if (request.headerField("content-type").isEmpty() && ((request.d->uploadByteDevice && request.d->uploadByteDevice->size() > 0) || request.d->url.hasQuery())) {
//Content-Type is mandatory. We can't say anything about the encoding, but x-www-form-urlencoded is the most likely to work.
//This warning indicates a bug in application code not setting a required header.
//Note that if using QHttpMultipart, the content-type is set in QNetworkAccessManagerPrivate::prepareMultipart already