Skip to content

Commit

Permalink
Added last modification time/date for static files being compiled dat…
Browse files Browse the repository at this point in the history
…e time
  • Loading branch information
rikkimax committed Apr 18, 2014
1 parent 2067a07 commit 67f32ac
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
4 changes: 4 additions & 0 deletions source/base/cmsed/base/internal/registration/staticfiles.d
Original file line number Diff line number Diff line change
@@ -1,10 1,12 @@
module cmsed.base.internal.registration.staticfiles;
import cmsed.base.internal.routing;
import cmsed.base.mimetypes;
import cmsed.base.util;
import cmsed.minifier.jsmin;
import vibe.d;
import std.path : extension;
import std.string : toLower;
import std.datetime;

private shared {
ubyte[][string] staticFiles;
Expand Down Expand Up @@ -59,6 61,8 @@ void configureStaticFiles() {
string path = http_request.path[staticPath.length .. $].toLower();

if (path in staticFiles) {
http_response.headers["Cache-Control"] = "No-Store, must-revalidate";
http_response.headers["Last-Modified"] = utc0CompiledTimeStamp();
http_response.writeBody(cast(ubyte[])staticFiles[path], staticTypes[path]);
}
}
Expand Down
33 changes: 31 additions & 2 deletions source/base/cmsed/base/util.d
Original file line number Diff line number Diff line change
@@ -1,7 1,7 @@
module cmsed.base.util;
import std.uni : toLower;
import std.datetime : SysTime, Clock;
import std.string : indexOf;
import std.string : indexOf, toUpper, toLower;
import std.conv : to;
import core.time : Duration;

/**
Expand All @@ -20,6 20,35 @@ SysTime utc0SysTime() {
return curr;
}

string utc0CompiledTimeStamp() {
string timestamp = __TIMESTAMP__;
string[] values = timestamp.split(" ");

string timeo;
timeo ~= values[4] ~ "-";
timeo ~= values[1] ~ "-";
timeo ~= values[2] ~ " ";
timeo ~= values[3];

SysTime time = SysTime.fromSimpleString(timeo);
auto durr = Clock.currTime().utcOffset;
time -= durr;

string dayOfWeek = to!string(time.dayOfWeek);
string month = to!string(time.month);
dayOfWeek = cast(char)toUpper(dayOfWeek[0]) ~ dayOfWeek[1 .. $];
month = cast(char)toUpper(month[0]) ~ month[1 .. $];

string output;
output ~= dayOfWeek ~ ", ";
output ~= to!string(time.day) ~ " ";
output ~= month ~ " ";
output ~= to!string(time.year) ~ " ";
output ~= time.toSimpleString().split(" ")[1] ~ " GMT";

return output;
}

/**
* Get the UTC offset time
*/
Expand Down

0 comments on commit 67f32ac

Please sign in to comment.