mirror of
https://github.com/FraMecca/Buridans_donkey.git
synced 2024-03-20 11:20:15 +01:00
use of unions in handleRequest
This commit is contained in:
parent
a98f547c8b
commit
bab409758c
1 changed files with 18 additions and 6 deletions
|
@ -75,14 +75,26 @@ if (gen == "/dev/random" || gen == "/dev/urandom")
|
|||
|
||||
void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res)
|
||||
{
|
||||
void error(){
|
||||
res.statusCode = 400;
|
||||
}
|
||||
|
||||
immutable path = req.requestPath.bySegment.array;
|
||||
enforce(path.length == 3); // path[0] == ""
|
||||
auto engine = path[1].toString;
|
||||
auto args = path[2].toString.split(",");
|
||||
if(path.length != 3){// path[0] == ""
|
||||
error();
|
||||
return ;
|
||||
}
|
||||
|
||||
auto engine = path[1].name;
|
||||
auto args = path[2].name.split(",");
|
||||
const result = shuffle(args, engine);
|
||||
immutable body = "Asino says:</br><ul>" ~ "<li>" ~ result.join("</li><li>") ~ "</ul>";
|
||||
res.headers["Content-Type"] = "text/html";
|
||||
res.writeBody(body);
|
||||
result.visit!((string [] r) {
|
||||
immutable body = "Asino says:</br><ul>" ~ "<li>" ~ r.join("</li><li>") ~ "</ul>";
|
||||
res.headers["Content-Type"] = "text/html";
|
||||
res.writeBody(body);
|
||||
},
|
||||
(Error e) { error(); }
|
||||
);
|
||||
}
|
||||
|
||||
shared static this()
|
||||
|
|
Loading…
Reference in a new issue