use of unions in handleRequest

This commit is contained in:
Francesco Mecca 2019-04-27 09:23:23 +02:00
parent a98f547c8b
commit bab409758c

View file

@ -75,14 +75,26 @@ if (gen == "/dev/random" || gen == "/dev/urandom")
void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res) void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res)
{ {
void error(){
res.statusCode = 400;
}
immutable path = req.requestPath.bySegment.array; immutable path = req.requestPath.bySegment.array;
enforce(path.length == 3); // path[0] == "" if(path.length != 3){// path[0] == ""
auto engine = path[1].toString; error();
auto args = path[2].toString.split(","); return ;
}
auto engine = path[1].name;
auto args = path[2].name.split(",");
const result = shuffle(args, engine); const result = shuffle(args, engine);
immutable body = "Asino says:</br><ul>" ~ "<li>" ~ result.join("</li><li>") ~ "</ul>"; result.visit!((string [] r) {
res.headers["Content-Type"] = "text/html"; immutable body = "Asino says:</br><ul>" ~ "<li>" ~ r.join("</li><li>") ~ "</ul>";
res.writeBody(body); res.headers["Content-Type"] = "text/html";
res.writeBody(body);
},
(Error e) { error(); }
);
} }
shared static this() shared static this()