PageCompiler: add support for Cache-Control header

This commit is contained in:
Günter Obiltschnig
2018-08-08 11:04:31 +02:00
parent b7ac69ebc6
commit 148ba9ab72
2 changed files with 10 additions and 0 deletions

View File

@@ -272,6 +272,11 @@ is actually written to a string stream (<[std::ostringstream]>).
Sending of the HTTP response back to the client is deferred to Sending of the HTTP response back to the client is deferred to
when the page is complete. when the page is complete.
!cacheControl
If set to a non-empty string (e.g., "no-cache, no-store"), adds a "Cache-Control"
header to the response with the given argument as value.
!session (OSP only) !session (OSP only)
For use with the POCO Open Service Platform only. For use with the POCO Open Service Platform only.

View File

@@ -311,6 +311,7 @@ void CodeWriter::writeResponse(std::ostream& ostr)
{ {
std::string contentType(_page.get("page.contentType", "text/html")); std::string contentType(_page.get("page.contentType", "text/html"));
std::string contentLang(_page.get("page.contentLanguage", "")); std::string contentLang(_page.get("page.contentLanguage", ""));
std::string cacheControl(_page.get("page.cacheControl", ""));
bool buffered(_page.getBool("page.buffered", false)); bool buffered(_page.getBool("page.buffered", false));
bool chunked(_page.getBool("page.chunked", !buffered)); bool chunked(_page.getBool("page.chunked", !buffered));
bool compressed(_page.getBool("page.compressed", false)); bool compressed(_page.getBool("page.compressed", false));
@@ -333,6 +334,10 @@ void CodeWriter::writeResponse(std::ostream& ostr)
ostr << "\tbool _compressResponse(request.hasToken(\"Accept-Encoding\", \"gzip\"));\n" ostr << "\tbool _compressResponse(request.hasToken(\"Accept-Encoding\", \"gzip\"));\n"
<< "\tif (_compressResponse) response.set(\"Content-Encoding\", \"gzip\");\n"; << "\tif (_compressResponse) response.set(\"Content-Encoding\", \"gzip\");\n";
} }
if (!cacheControl.empty())
{
ostr << "\tresponse.set(\"Cache-Control\", \"" << cacheControl << "\");\n";
}
ostr << "\n"; ostr << "\n";
} }