diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2022-01-13 16:37:01 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2022-01-18 18:50:10 +0100 |
commit | 92959fe57ff106c3a043eedb8503271348a8e8d8 (patch) | |
tree | 0ce04c8dd5981d356f04257a9145d15e566cfeaf /tests/auto | |
parent | a913bd51eef855b22faef91c4f40459a4cd82b21 (diff) | |
download | qtbase-92959fe57ff106c3a043eedb8503271348a8e8d8.tar.gz |
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
Change-Id: I2792bce14a07be025cf551b0594630260c112269
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit aa8fd6bc39f929a2bfad6bba4bf26e69624cd88a)
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp b/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp index 6637be0174..654dc159ad 100644 --- a/tests/auto/network/access/qnetworkrequest/tst_qnetworkrequest.cpp +++ b/tests/auto/network/access/qnetworkrequest/tst_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 test suite of the Qt Toolkit. @@ -26,9 +26,11 @@ ** ****************************************************************************/ - -#include <QtTest/QtTest> +#include <QTest> #include <QtCore/QUrl> +#if QT_CONFIG(timezone) +# include <QtCore/QTimeZone> +#endif #include <QtNetwork/QNetworkRequest> #include <QtNetwork/QNetworkCookie> @@ -236,12 +238,28 @@ void tst_QNetworkRequest::setHeader_data() << QVariant(QDate(2007, 11, 01)) << true << "Last-Modified" << "Thu, 01 Nov 2007 00:00:00 GMT"; - QTest::newRow("Last-Modified-DateTime") << QNetworkRequest::LastModifiedHeader - << QVariant(QDateTime(QDate(2007, 11, 01), - QTime(18, 8, 30), - Qt::UTC)) - << true << "Last-Modified" - << "Thu, 01 Nov 2007 18:08:30 GMT"; + QTest::newRow("Last-Modified-DateTime-UTC") + << QNetworkRequest::LastModifiedHeader + << QVariant(QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30), Qt::UTC)) + << true << "Last-Modified" << "Thu, 01 Nov 2007 18:08:30 GMT"; + // QTBUG-80666: format dates correctly (as GMT) even if the date passed in isn't in UTC: + QTest::newRow("Last-Modified-DateTime-Local") + << QNetworkRequest::LastModifiedHeader + << QVariant(QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30), Qt::UTC).toLocalTime()) + << true << "Last-Modified" << "Thu, 01 Nov 2007 18:08:30 GMT"; + QTest::newRow("Last-Modified-DateTime-Offset") + << QNetworkRequest::LastModifiedHeader + << QVariant(QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30), Qt::UTC).toOffsetFromUtc(3600)) + << true << "Last-Modified" << "Thu, 01 Nov 2007 18:08:30 GMT"; +#if QT_CONFIG(timezone) + QTimeZone cet("Europe/Oslo"); + if (cet.isValid()) { + QTest::newRow("Last-Modified-DateTime-CET") + << QNetworkRequest::LastModifiedHeader + << QVariant(QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30), Qt::UTC).toTimeZone(cet)) + << true << "Last-Modified" << "Thu, 01 Nov 2007 18:08:30 GMT"; + } +#endif QTest::newRow("If-Modified-Since-Date") << QNetworkRequest::IfModifiedSinceHeader << QVariant(QDate(2017, 7, 01)) |