use of io.vertx.core.http.HttpHeaders.CONTENT_TYPE in project vertx-openshift-it by cescoffier.
the class MainVerticle method start.
@Override
public void start() {
vertx.createHttpServer().requestHandler(req -> {
String path = req.path();
HttpServerResponse response = req.response();
switch(path) {
case "/":
response.end("Hello Vert.x!");
break;
case "/file":
response.sendFile("/app/config/application.properties");
break;
case "/tmp":
response.sendFile("/tmp/hello.txt");
break;
case "/headers":
json(ok(response)).end(headersToJson(req.headers()).encode());
break;
case "/host":
ok(response).putHeader(CONTENT_TYPE, "text/plain").end(System.getenv("HOSTNAME"));
break;
case "/form":
response.setChunked(true);
req.setExpectMultipart(true);
req.endHandler((v) -> {
JsonObject json = new JsonObject();
for (String attr : req.formAttributes().names()) {
json.put(attr, req.formAttributes().get(attr));
}
ok(json(response)).end(json.encode());
});
break;
case "/write":
writeSomeFile(response);
break;
}
}).websocketHandler(socket -> {
if (!socket.path().equals("/ws")) {
socket.reject();
} else {
socket.handler(socket::writeBinaryMessage);
}
}).listen(8080);
}
Aggregations