@Override public void start() throws Exception { HttpServer server = vertx.createHttpServer(); server.requestStream().toObservable().subscribe(req -> { HttpServerResponse resp = req.response(); String contentType = req.getHeader("Content-Type"); if (contentType != null) { resp.putHeader("Content-Type", contentType); } resp.setChunked(true); req.toObservable().subscribe( resp::write, err -> {}, resp::end ); }); server.listen(8080); } }
protected void requireLogin(RoutingContext context, BiConsumer<RoutingContext, JsonObject> biHandler) { Optional<JsonObject> principal = Optional.ofNullable(context.request().getHeader("user-principal")) .map(JsonObject::new); if (principal.isPresent()) { biHandler.accept(context, principal.get()); } else { context.response() .setStatusCode(401) .end(new JsonObject().put("message", "need_auth").encode()); } }