【发布时间】:2020-04-12 04:51:09
【问题描述】:
对于邮递员的每个请求,Vertx 处理程序都会调用两次。
我有两个处理程序,它们将在调用请求处理处理程序之前被调用。 一个用于设置标头,一个用于验证用户,但两者都调用了两次。
@Log4j2
public class BaseResponseHandler implements Handler<RoutingContext> {
@Override
public void handle(RoutingContext context) {
HttpServerResponse response = context.response();
log.info("Inside BaseResponse Handler!");
response.putHeader("Content-Security-Policy",
"script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'")
// do not allow proxies to cache the data
.putHeader("Cache-Control", "no-store, no-cache")
.putHeader("X-Content-Type-Options", "nosniff")
.putHeader("Strict-Transport-Security", "XYZ")
.putHeader("X-Download-Options", "XYZ")
.putHeader("X-XSS-Protection", "XYZ")
.putHeader("X-FRAME-OPTIONS", "XYZ");
response.setChunked(true);
context.next();
}
}
我在 httpServerVerticle 中的片段
router.route().order(1).handler(new BaseResponseHandler());
router.route().order(0).handler(new AuthenticationHandler()::authenticate);
在我得到的日志中
10:09:54.214 [vert.x-eventloop-thread-4] [%vcl] DEBUG *.handlers.TokenHandler - User is Authenticated : io.vertx.ext.auth.jwt.impl.JWTUser@7855ebfa
10:09:54.215 [vert.x-eventloop-thread-4] [%vcl] INFO *.handlers.BaseResponseHandler - Inside BaseResponse Handler!
10:09:54.243 [vert.x-eventloop-thread-4] [%vcl] DEBUG *.handlers.TokenHandler - User is Authenticated : io.vertx.ext.auth.jwt.impl.JWTUser@5fb3053a
10:09:54.243 [vert.x-eventloop-thread-4] [%vcl] INFO *.handlers.BaseResponseHandler - Inside BaseResponse Handler!
【问题讨论】:
标签: vert.x