Browse Source

Send Date http header

It's not strict required but often expected.
change class to namespace
cleanup header
adaptive-webui-19844
Chocobo1 8 years ago
parent
commit
4b2266a8e2
  1. 15
      src/base/http/responsegenerator.cpp
  2. 6
      src/base/http/responsegenerator.h
  3. 1
      src/base/http/types.h

15
src/base/http/responsegenerator.cpp

@ -29,9 +29,12 @@ @@ -29,9 +29,12 @@
* Contact : chris@qbittorrent.org
*/
#include "base/utils/gzip.h"
#include "responsegenerator.h"
#include <QDateTime>
#include "base/utils/gzip.h"
using namespace Http;
QByteArray ResponseGenerator::generate(Response response)
@ -49,6 +52,7 @@ 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) @@ -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"));
}

6
src/base/http/responsegenerator.h

@ -37,10 +37,10 @@ @@ -37,10 +37,10 @@
namespace Http
{
class ResponseGenerator
namespace ResponseGenerator
{
public:
static QByteArray generate(Response response);
QByteArray generate(Response response);
QString httpDate();
};
}

1
src/base/http/types.h

@ -47,6 +47,7 @@ namespace Http @@ -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";

Loading…
Cancel
Save