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 <jocelyn.turcotte@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Allan Sandfeld Jensen 2014-11-12 16:58:15 +01:00 committed by Allan Sandfeld Jensen
parent 9990e47f04
commit ccd4da392c
1 changed files with 1 additions and 1 deletions

View File

@ -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