如何在WebFlux中访问用于Spring数据审核的http标头



我正在尝试使用http头来审计我的Spring存储库,如这里所述https://docs.spring.io/spring-data/commons/docs/current/reference/html/#auditing.reactive-审计师意识

但我面临的挑战是,我不使用Spring Security,我的userId在http头中是纯文本的。

我甚至发现,在WebFlux的情况下,我需要使用Reactor Context,如果我理解正确,已经有一个过滤器可以做到这一点:https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/filter/reactive/ServerWebExchangeContextFilter.html,但我很难写代码来提取它。

有人知道有什么文章/博客/片段可以为我指明正确的方向吗?

ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
// get the request
HttpServletRequest request = requestAttributes.getRequest();
// get headers
username = request.getHeader("x-username");

我不确定WebFlux是否可以工作