summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-02-21 00:51:41 +0000
committerrandomdan <randomdan@localhost>2013-02-21 00:51:41 +0000
commit0bc3e2e53fed0b92119fa5c0bd1d3959764d7a14 (patch)
treeee2cfc5563e650a48762566413ac48977a14ddfa
parentFix bug with lookups introduced in 761 (diff)
downloadproject2-0bc3e2e53fed0b92119fa5c0bd1d3959764d7a14.tar.bz2
project2-0bc3e2e53fed0b92119fa5c0bd1d3959764d7a14.tar.xz
project2-0bc3e2e53fed0b92119fa5c0bd1d3959764d7a14.zip
Simple support for redirect on request complete
-rw-r--r--project2/cgi/cgiAppEngine.h3
-rw-r--r--project2/cgi/cgiStageRequest.cpp17
2 files changed, 16 insertions, 4 deletions
diff --git a/project2/cgi/cgiAppEngine.h b/project2/cgi/cgiAppEngine.h
index 147ebe8..50c9a7f 100644
--- a/project2/cgi/cgiAppEngine.h
+++ b/project2/cgi/cgiAppEngine.h
@@ -92,7 +92,8 @@ class CgiApplicationEngine : public ApplicationEngine, public TransformChainLink
virtual NextStage run();
virtual HttpHeaderPtr getHeader() const;
protected:
- std::string present;
+ Variable present;
+ Variable redirect;
};
/// Stage to process GET requests and follow up RequestStages
diff --git a/project2/cgi/cgiStageRequest.cpp b/project2/cgi/cgiStageRequest.cpp
index 967365a..8fa06bf 100644
--- a/project2/cgi/cgiStageRequest.cpp
+++ b/project2/cgi/cgiStageRequest.cpp
@@ -11,7 +11,8 @@ CgiApplicationEngine::RequestStage::RequestStage(ScriptReaderPtr s) :
::CheckHost(s->root()),
CgiApplicationEngine::ResponseStage(s->root()),
::TaskHost(s->root()),
- present(s->root()->value("present","").as<std::string>())
+ present(s->root(), "present", Null()),
+ redirect(s->root(), "redirect", Null())
{
}
@@ -20,13 +21,23 @@ CgiApplicationEngine::RequestStage::run()
{
runChecks();
execute();
- return NextStage(present.empty() ? NULL : new PresentStage(env()->resolveScript(env()->presentRoot, present, false)), this);
+ if (!present().isNull()) {
+ return NextStage(new PresentStage(env()->resolveScript(env()->presentRoot, present(), false)), this);
+ }
+ return NextStage(NULL, this);
}
CgiApplicationEngine::HttpHeaderPtr
CgiApplicationEngine::RequestStage::getHeader() const
{
- Project2HttpHeader * header = new Project2HttpHeader("200 OK");
+ Project2HttpHeader * header;
+ if (redirect().isNull()) {
+ header = new Project2HttpHeader("200 OK");
+ }
+ else {
+ header = new Project2HttpHeader("301 Moved Permanently");
+ header->addHeader("Location", redirect());
+ }
header->addHeader("Cache-control", "no-cache");
return HttpHeaderPtr(header);
}