有没有办法在请求处理程序中获取Reactor Netty中使用的ByteBuf分配器?类似于在纯Netty中如何final ByteBufAllocator byteBufAllocator = ctx.alloc();
?
HttpServer.create()
.host("0.0.0.0")
.port(8080)
.route(routes -> {
routes.ws("/ws", (in, out) ->
// how to get the allocator here?
});
})
答案 0 :(得分:1)
您可以像这样从ByteBufAllocator
或WebSocketOutbound
访问HttpServerResponse
:
HttpServer.create()
.host("0.0.0.0")
.port(8080)
.route(routes -> routes
.ws("/ws", (in, out) -> {
ByteBufAllocator alloc = out.alloc();
// ...
})
.get("/path", (request, response) -> {
ByteBufAllocator alloc = response.alloc();
// ...
})
);