From 4b2266a8e23d262b2ad7ce7b63a44ef70f1e90e9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 12 Apr 2017 23:57:21 +0800 Subject: [PATCH] Send Date http header It's not strict required but often expected. change class to namespace cleanup header --- src/base/http/responsegenerator.cpp | 15 ++++++++++++++- src/base/http/responsegenerator.h | 6 +++--- src/base/http/types.h | 1 + 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/base/http/responsegenerator.cpp b/src/base/http/responsegenerator.cpp index c59459bc1..378396722 100644 --- a/src/base/http/responsegenerator.cpp +++ b/src/base/http/responsegenerator.cpp @@ -29,9 +29,12 @@ * Contact : chris@qbittorrent.org */ -#include "base/utils/gzip.h" #include "responsegenerator.h" +#include + +#include "base/utils/gzip.h" + using namespace Http; QByteArray ResponseGenerator::generate(Response response) @@ -49,6 +52,7 @@ QByteArray ResponseGenerator::generate(Response response) } response.headers[HEADER_CONTENT_LENGTH] = QString::number(response.content.length()); + response.headers[HEADER_DATE] = httpDate(); QString ret(QLatin1String("HTTP/1.1 %1 %2\r\n%3\r\n")); @@ -64,3 +68,12 @@ QByteArray ResponseGenerator::generate(Response response) return ret.toUtf8() + response.content; } + +QString ResponseGenerator::httpDate() +{ + // [RFC 7231] 7.1.1.1. Date/Time Formats + // example: "Sun, 06 Nov 1994 08:49:37 GMT" + + return QLocale::c().toString(QDateTime::currentDateTimeUtc(), QLatin1String("ddd, dd MMM yyyy HH:mm:ss")) + .append(QLatin1String(" GMT")); +} diff --git a/src/base/http/responsegenerator.h b/src/base/http/responsegenerator.h index e12b5c344..3d41f7444 100644 --- a/src/base/http/responsegenerator.h +++ b/src/base/http/responsegenerator.h @@ -37,10 +37,10 @@ namespace Http { - class ResponseGenerator + namespace ResponseGenerator { - public: - static QByteArray generate(Response response); + QByteArray generate(Response response); + QString httpDate(); }; } diff --git a/src/base/http/types.h b/src/base/http/types.h index a8dc9a898..22d55b3cd 100644 --- a/src/base/http/types.h +++ b/src/base/http/types.h @@ -47,6 +47,7 @@ namespace Http const QString HEADER_X_XSS_PROTECTION = "X-XSS-Protection"; const QString HEADER_X_CONTENT_TYPE_OPTIONS = "X-Content-Type-Options"; const QString HEADER_CONTENT_SECURITY_POLICY = "Content-Security-Policy"; + const QString HEADER_DATE = "Date"; const QString CONTENT_TYPE_CSS = "text/css; charset=UTF-8"; const QString CONTENT_TYPE_GIF = "image/gif";