|
|
@@ -1,7 +1,7 @@
|
|
|
//
|
|
|
// CodeWriter.cpp
|
|
|
//
|
|
|
-// $Id: //poco/1.4/PageCompiler/src/CodeWriter.cpp#2 $
|
|
|
+// $Id: //poco/1.4/PageCompiler/src/CodeWriter.cpp#3 $
|
|
|
//
|
|
|
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
|
|
// and Contributors.
|
|
|
@@ -34,6 +34,7 @@
|
|
|
#include "Page.h"
|
|
|
#include "Poco/Path.h"
|
|
|
#include "Poco/StringTokenizer.h"
|
|
|
+#include "Poco/String.h"
|
|
|
|
|
|
|
|
|
using Poco::Path;
|
|
|
@@ -76,6 +77,10 @@ void CodeWriter::writeImpl(std::ostream& ostr, const std::string& headerFileName
|
|
|
{
|
|
|
ostr << "#include \"" << headerFileName << "\"\n";
|
|
|
writeImplIncludes(ostr);
|
|
|
+ if (_page.getBool("page.compressed", false))
|
|
|
+ {
|
|
|
+ ostr << "#include \"Poco/DeflatingStream.h\"\n";
|
|
|
+ }
|
|
|
if (_page.getBool("page.buffered", false))
|
|
|
{
|
|
|
ostr << "#include \"Poco/StreamCopier.h\"\n";
|
|
|
@@ -90,6 +95,13 @@ void CodeWriter::writeImpl(std::ostream& ostr, const std::string& headerFileName
|
|
|
}
|
|
|
|
|
|
beginNamespace(ostr);
|
|
|
+
|
|
|
+ std::string path = _page.get("page.path", "");
|
|
|
+ if (!path.empty())
|
|
|
+ {
|
|
|
+ ostr << "\tconst std::string " << _class << "::PATH(\"" << path << "\");\n\n\n";
|
|
|
+ }
|
|
|
+
|
|
|
writeConstructor(ostr);
|
|
|
writeHandler(ostr);
|
|
|
writeFactory(ostr);
|
|
|
@@ -132,7 +144,9 @@ void CodeWriter::beginGuard(std::ostream& ostr, const std::string& headerFileNam
|
|
|
{
|
|
|
Path p(headerFileName);
|
|
|
std::string guard(p.getBaseName());
|
|
|
+ Poco::translateInPlace(guard, ".-", "__");
|
|
|
guard += "_INCLUDED";
|
|
|
+
|
|
|
ostr << "#ifndef " << guard << "\n";
|
|
|
ostr << "#define " << guard << "\n";
|
|
|
ostr << "\n\n";
|
|
|
@@ -143,6 +157,7 @@ void CodeWriter::endGuard(std::ostream& ostr, const std::string& headerFileName)
|
|
|
{
|
|
|
Path p(headerFileName);
|
|
|
std::string guard(p.getBaseName());
|
|
|
+ Poco::translateInPlace(guard, ".-", "__");
|
|
|
guard += "_INCLUDED";
|
|
|
ostr << "\n\n";
|
|
|
ostr << "#endif // " << guard << "\n";
|
|
|
@@ -164,6 +179,13 @@ void CodeWriter::handlerClass(std::ostream& ostr, const std::string& base, const
|
|
|
}
|
|
|
ostr << "\tvoid handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);\n";
|
|
|
writeHandlerMembers(ostr);
|
|
|
+
|
|
|
+ std::string path = _page.get("page.path", "");
|
|
|
+ if (!path.empty())
|
|
|
+ {
|
|
|
+ ostr << "\n\tstatic const std::string PATH;\n";
|
|
|
+ }
|
|
|
+
|
|
|
ostr << "};\n";
|
|
|
}
|
|
|
|
|
|
@@ -313,7 +335,10 @@ void CodeWriter::writeResponse(std::ostream& ostr)
|
|
|
std::string contentLang(_page.get("page.contentLanguage", ""));
|
|
|
bool buffered(_page.getBool("page.buffered", false));
|
|
|
bool chunked(_page.getBool("page.chunked", !buffered));
|
|
|
-
|
|
|
+ bool compressed(_page.getBool("page.compressed", false));
|
|
|
+ if (buffered) compressed = false;
|
|
|
+ if (compressed) chunked = true;
|
|
|
+
|
|
|
if (chunked)
|
|
|
{
|
|
|
ostr << "\tresponse.setChunkedTransferEncoding(true);\n";
|
|
|
@@ -325,6 +350,11 @@ void CodeWriter::writeResponse(std::ostream& ostr)
|
|
|
ostr << "\tif (request.has(\"Accept-Language\"))\n"
|
|
|
<< "\t\tresponse.set(\"Content-Language\", \"" << contentLang << "\");\n";
|
|
|
}
|
|
|
+ if (compressed)
|
|
|
+ {
|
|
|
+ ostr << "\tbool _compressResponse(request.hasToken(\"Accept-Encoding\", \"gzip\"));\n"
|
|
|
+ << "\tif (_compressResponse) response.set(\"Content-Encoding\", \"gzip\");\n";
|
|
|
+ }
|
|
|
ostr << "\n";
|
|
|
}
|
|
|
|
|
|
@@ -333,6 +363,10 @@ void CodeWriter::writeContent(std::ostream& ostr)
|
|
|
{
|
|
|
bool buffered(_page.getBool("page.buffered", false));
|
|
|
bool chunked(_page.getBool("page.chunked", !buffered));
|
|
|
+ bool compressed(_page.getBool("page.compressed", false));
|
|
|
+ int compressionLevel(_page.getInt("page.compressionLevel", 1));
|
|
|
+ if (buffered) compressed = false;
|
|
|
+ if (compressed) chunked = true;
|
|
|
|
|
|
if (buffered)
|
|
|
{
|
|
|
@@ -344,6 +378,14 @@ void CodeWriter::writeContent(std::ostream& ostr)
|
|
|
}
|
|
|
ostr << "\tPoco::StreamCopier::copyStream(responseStream, response.send());\n";
|
|
|
}
|
|
|
+ else if (compressed)
|
|
|
+ {
|
|
|
+ ostr << "\tstd::ostream& _responseStream = response.send();\n"
|
|
|
+ << "\tPoco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, " << compressionLevel << ");\n"
|
|
|
+ << "\tstd::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream;\n";
|
|
|
+ ostr << _page.handler().str();
|
|
|
+ ostr << "\tif (_compressResponse) _gzipStream.close();\n";
|
|
|
+ }
|
|
|
else
|
|
|
{
|
|
|
ostr << "\tstd::ostream& responseStream = response.send();\n";
|