mirror of
https://github.com/pocoproject/poco.git
synced 2025-05-02 23:42:29 +02:00
improvements to PageCompiler (new precondition page attribute)
This commit is contained in:
parent
9f751f5e9a
commit
ecefa6121c
@ -2,7 +2,8 @@ POCO C++ Server Page Compiler User Guide
|
||||
PageCompiler
|
||||
|
||||
!!!Introduction
|
||||
PageCompiler is a command line tool that translates HTML files (and other kinds of files), into
|
||||
PageCompiler is a command line tool that translates HTML files (and other kinds of files, such as
|
||||
cascading style sheet files), into
|
||||
C++ code, more precisely, subclasses of Poco::Net::HTTPRequestHandler.
|
||||
The source files can contain special directives that allow it to include C++ code into
|
||||
the source file. The syntax of this directives is based on the syntax used for
|
||||
@ -179,6 +180,53 @@ Allows you to specify whether the response is sent using chunked transfer encodi
|
||||
Defaults to <[true]>.
|
||||
Set the value to <[false]> to disable chunked transfer encoding.
|
||||
|
||||
!precondition
|
||||
|
||||
Allows the specification of a precondition, which must be a C++ expression
|
||||
valid in the context of the request handler. This can be used to implement
|
||||
authentication.
|
||||
|
||||
Example:
|
||||
|
||||
<%@ page
|
||||
class="AuthSamplePage"
|
||||
precondition="checkCredentials(request, response)"
|
||||
%>
|
||||
|
||||
<%!
|
||||
bool checkCredentials(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
|
||||
{
|
||||
bool isAuthenticated = false;
|
||||
if (request.hasCredentials())
|
||||
{
|
||||
std::string scheme;
|
||||
std::string authInfo;
|
||||
request.getCredentials(scheme, authInfo);
|
||||
if (scheme == Poco::Net::HTTPBasicCredentials::SCHEME)
|
||||
{
|
||||
Poco::Net::HTTPBasicCredentials cred(request);
|
||||
isAuthenticated = (cred.getUsername() == "joeuser" && cred.getPassword() == "s3cr3t");
|
||||
}
|
||||
}
|
||||
if (!isAuthenticated)
|
||||
{
|
||||
response.requireAuthentication("Restricted Area");
|
||||
response.send();
|
||||
}
|
||||
return isAuthenticated;
|
||||
}
|
||||
%>
|
||||
<html>
|
||||
<head>
|
||||
<title>Restricted Area</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Restricted Area</h1>
|
||||
</body>
|
||||
</html>
|
||||
----
|
||||
|
||||
|
||||
!session (OSP only)
|
||||
|
||||
For use with the POCO Open Service Platform only.
|
||||
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// CodeWriter.cpp
|
||||
//
|
||||
// $Id: //poco/Main/PageCompiler/src/CodeWriter.cpp#1 $
|
||||
// $Id: //poco/1.3/PageCompiler/src/CodeWriter.cpp#1 $
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@ -234,6 +234,10 @@ void CodeWriter::writeHandler(std::ostream& ostr)
|
||||
{
|
||||
ostr << "void " << _class << "::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)\n";
|
||||
ostr << "{\n";
|
||||
if (_page.has("page.precondition"))
|
||||
{
|
||||
ostr << "\tif (!(" << _page.get("page.precondition") << ")) return;\n\n";
|
||||
}
|
||||
writeSession(ostr);
|
||||
writeForm(ostr);
|
||||
writeRequest(ostr);
|
||||
@ -289,4 +293,5 @@ void CodeWriter::writeRequest(std::ostream& ostr)
|
||||
ostr << "\tresponse.setContentType(\"" << contentType << "\");\n";
|
||||
ostr << "\n";
|
||||
ostr << "\tstd::ostream& ostr = response.send();\n";
|
||||
ostr << "\tif (request.getMethod() == Poco::Net::HTTPRequest::HTTP_HEAD) return;\n";
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
//
|
||||
// CodeWriter.h
|
||||
//
|
||||
// $Id: //poco/Main/PageCompiler/src/CodeWriter.h#1 $
|
||||
// $Id: //poco/1.3/PageCompiler/src/CodeWriter.h#1 $
|
||||
//
|
||||
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
@ -50,7 +50,7 @@ public:
|
||||
CodeWriter(const Page& page, const std::string& clazz);
|
||||
/// Creates the CodeWriter, using the given Page.
|
||||
|
||||
~CodeWriter();
|
||||
virtual ~CodeWriter();
|
||||
/// Destroys the PageReader.
|
||||
|
||||
virtual void writeHeader(std::ostream& ostr, const std::string& headerFileName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user