diff options
author | David Kalnischkies <kalnischkies@gmail.com> | 2012-07-11 11:07:54 +0200 |
---|---|---|
committer | David Kalnischkies <kalnischkies@gmail.com> | 2012-07-11 11:07:54 +0200 |
commit | d37911acee3eb34368e6d9e6a0046c9150d2bce6 (patch) | |
tree | 37c553558066d31df87e3aa1a94cdbac3019f48a /test/interactive-helper | |
parent | 3522b1a8f16f45cf9c0c45b8b86cc886f1368df4 (diff) |
add simple url rewriting to the webserver
Diffstat (limited to 'test/interactive-helper')
-rw-r--r-- | test/interactive-helper/aptwebserver.cc | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/test/interactive-helper/aptwebserver.cc b/test/interactive-helper/aptwebserver.cc index 2052fe6d8..7fa322ea9 100644 --- a/test/interactive-helper/aptwebserver.cc +++ b/test/interactive-helper/aptwebserver.cc @@ -137,7 +137,7 @@ void sendError(int const client, int const httpcode, std::string const &request, std::list<std::string> headers; std::string response("<html><head><title>"); response.append(httpcodeToStr(httpcode)).append("</title></head>"); - response.append("<body><h1>").append(httpcodeToStr(httpcode)).append("</h1"); + response.append("<body><h1>").append(httpcodeToStr(httpcode)).append("</h1>"); response.append("This error is a result of the request: <pre>"); response.append(request).append("</pre></body></html>"); addDataHeaders(headers, response); @@ -255,6 +255,8 @@ int main(int const argc, const char * argv[]) {0, "simulate-paywall", "aptwebserver::Simulate-Paywall", CommandLine::Boolean}, {0, "port", "aptwebserver::port", CommandLine::HasArg}, + {'c',"config-file",0,CommandLine::ConfigFile}, + {'o',"option",0,CommandLine::ArbItem}, {0,0,0,0} }; @@ -366,7 +368,20 @@ int main(int const argc, const char * argv[]) sendRedirect(client, 301, filename.append("/"), *m, sendContent); } else - sendError(client, 404, *m, false); + { + ::Configuration::Item const *Replaces = _config->Tree("aptwebserver::redirect::replace"); + if (Replaces != NULL) { + std::string redirect = "/" + filename; + for (::Configuration::Item *I = Replaces->Child; I != NULL; I = I->Next) + redirect = SubstVar(redirect, I->Tag, I->Value); + redirect.erase(0,1); + if (redirect != filename) { + sendRedirect(client, 301, redirect, *m, sendContent); + continue; + } + } + sendError(client, 404, *m, sendContent); + } } _error->DumpErrors(std::cerr); messages.clear(); |