summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkrequest.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2022-01-13 16:37:01 +0100
committerEdward Welbourne <edward.welbourne@qt.io>2022-01-17 22:29:30 +0100
commitaa8fd6bc39f929a2bfad6bba4bf26e69624cd88a (patch)
tree43b2c216b55faf73a1b9198cc58586b063cb4781 /src/network/access/qnetworkrequest.cpp
parent21735f24cf05cac5ef6f94c1fe2058b6e06ae67e (diff)
Convert date-time to UTC before claiming it's in GMT
QNetworkHeadersPrivate::toHttpDate() used a custom format to output a date-time; the format supplied GMT as suffix, but neglected to convert the date-time to UTC, so local-time was formatted as if it were UTC, regardless of its actual offset from it. Fixing this (by the obvious toUTC() call) broke formatting when the supplied header value was a QDate, since it's packaged as a QVariant and QVariant's conversion of QDate to QDateTime uses local time's (not UTC's) start of day. So fix headerValue() to separate QDate and QDateTime cases and use startOfDay(Qt::UTC) to get the right start of the day. Added tests for non-UTC date-times appearing correctly in HTTP headers. Fixes: QTBUG-80666 Pick-to: 6.3 6.2 6.2.3 5.15 Change-Id: I2792bce14a07be025cf551b0594630260c112269 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/access/qnetworkrequest.cpp')
-rw-r--r--src/network/access/qnetworkrequest.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index 64d35aa278..de40b2c088 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtNetwork module of the Qt Toolkit.
@@ -1071,9 +1071,10 @@ static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVaria
case QNetworkRequest::LastModifiedHeader:
case QNetworkRequest::IfModifiedSinceHeader:
switch (value.userType()) {
+ // Generate RFC 1123/822 dates:
case QMetaType::QDate:
+ return QNetworkHeadersPrivate::toHttpDate(value.toDate().startOfDay(Qt::UTC));
case QMetaType::QDateTime:
- // generate RFC 1123/822 dates:
return QNetworkHeadersPrivate::toHttpDate(value.toDateTime());
default:
@@ -1515,8 +1516,7 @@ QDateTime QNetworkHeadersPrivate::fromHttpDate(const QByteArray &value)
QByteArray QNetworkHeadersPrivate::toHttpDate(const QDateTime &dt)
{
- return QLocale::c().toString(dt, u"ddd, dd MMM yyyy hh:mm:ss 'GMT'")
- .toLatin1();
+ return QLocale::c().toString(dt.toUTC(), u"ddd, dd MMM yyyy hh:mm:ss 'GMT'").toLatin1();
}
QT_END_NAMESPACE