RequestIdentityWebFilter implements WebFilter { @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { String requestIdentity = exchange.getRequest().getHeaders() .getFirst(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER); if (StringUtils.hasLength(requestIdentity)) { exchange.getResponse().getHeaders().add(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, requestIdentity); } return chain.filter(exchange); }  @Override Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain);  }
@Test void requestIdentityHeader() { MockServerHttpRequest request = MockServerHttpRequest .get(V2_API_PATH_PATTERN) .header(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, "request-id") .build(); this.exchange = MockServerWebExchange.from(request); MockitoAnnotations.initMocks(this); given(chain.filter(exchange)).willReturn(Mono.empty()); RequestIdentityWebFilter webFilter = new RequestIdentityWebFilter(); webFilter.filter(exchange, chain).block(); assertThat(exchange.getResponse().getHeaders().getFirst(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER)) .isEqualTo("request-id"); }
@Test void requestIdentityHeaderMissing() { MockServerHttpRequest request = MockServerHttpRequest .get(V2_API_PATH_PATTERN) .build(); this.exchange = MockServerWebExchange.from(request); MockitoAnnotations.initMocks(this); given(chain.filter(exchange)).willReturn(Mono.empty()); RequestIdentityWebFilter webFilter = new RequestIdentityWebFilter(); webFilter.filter(exchange, chain).block(); assertThat(exchange.getResponse().getHeaders().getFirst(ServiceBrokerRequest.REQUEST_IDENTITY_HEADER)).isNull(); }