Skip to content

Commit

Permalink
Added support for caching and expiration times.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrohrer committed Jul 1, 2019
1 parent c7b61ac commit 3d3dbf2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions network/web/server/PageGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ class PageGenerator {
virtual char *getMimeType( char *inGetRequestPath ) = 0;


/**
* Gets max age in seconds that a given path should be cached
* by the browser
* Defaults to 0 (no caching).
*/
virtual int getCacheMaxAge( char *inGetRequestPath ) {
return 0;
}


};

Expand Down
17 changes: 17 additions & 0 deletions network/web/server/RequestHandlingThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,23 @@ void RequestHandlingThread::run() {
sockStream->writeString(
"HTTP/1.0 200 OK\r\n" );


int cacheSeconds = mGenerator->getCacheMaxAge( filePathBuffer );

if( cacheSeconds == 0 ) {
sockStream->writeString( "cache-control: no-cache\r\n" );
}
else {
char *cacheString = autoSprintf(
"cache-control: private, max-age=%d\r\n",
cacheSeconds );

sockStream->writeString( cacheString );

delete [] cacheString;
}


char *mimeType = mGenerator->getMimeType( filePathBuffer );

sockStream->writeString( "Content-Type: " );
Expand Down

0 comments on commit 3d3dbf2

Please sign in to comment.