Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 36 additions & 3 deletions lib/src/StaticFileRouter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <iostream>
#include <algorithm>
#include <memory>
#include <ctime>
#include <fcntl.h>
#ifndef _WIN32
#include <sys/file.h>
Expand Down Expand Up @@ -385,8 +386,24 @@ void StaticFileRouter::sendStaticFileResponse(
{
resp->addHeader("Last-Modified",
fileStat.modifiedTimeStr_);
resp->addHeader("Expires",
"Thu, 01 Jan 1970 00:00:00 GMT");
if (staticFilesCacheTime_ > 0)
{
time_t expiry =
time(nullptr) +
static_cast<time_t>(staticFilesCacheTime_);
struct tm expiryTm;
#ifdef _WIN32
gmtime_s(&expiryTm, &expiry);
#else
gmtime_r(&expiry, &expiryTm);
#endif
char buf[64];
size_t len = strftime(buf,
sizeof(buf),
"%a, %d %b %Y %H:%M:%S GMT",
&expiryTm);
resp->addHeader("Expires", std::string(buf, len));
}
}
callback(resp);
return;
Expand Down Expand Up @@ -538,7 +555,23 @@ void StaticFileRouter::sendStaticFileResponse(
if (!fileStat.modifiedTimeStr_.empty())
{
resp->addHeader("Last-Modified", fileStat.modifiedTimeStr_);
resp->addHeader("Expires", "Thu, 01 Jan 1970 00:00:00 GMT");
if (staticFilesCacheTime_ > 0)
{
time_t expiry =
time(nullptr) + static_cast<time_t>(staticFilesCacheTime_);
struct tm expiryTm;
#ifdef _WIN32
gmtime_s(&expiryTm, &expiry);
#else
gmtime_r(&expiry, &expiryTm);
#endif
char buf[64];
size_t len = strftime(buf,
sizeof(buf),
"%a, %d %b %Y %H:%M:%S GMT",
&expiryTm);
resp->addHeader("Expires", std::string(buf, len));
}
}
if (enableRange_)
{
Expand Down
Loading