doc: 阅读webclient文档

This commit is contained in:
asahi
2025-06-03 12:55:01 +08:00
parent 5e565ecfc6
commit db56eddf84

View File

@@ -450,5 +450,25 @@ public class MultipartExchangeFilterFunction implements ExchangeFilterFunction {
}
}
```
## Attributes
可以向request中添加attributes并且可以通过attributes来影响filter中的行为
```java
WebClient client = WebClient.builder()
.filter((request, next) -> {
Optional<Object> usr = request.attribute("myAttribute");
// ...
})
.build();
client.get().uri("https://example.org/")
.attribute("myAttribute", "...")
.retrieve()
.bodyToMono(Void.class);
}
```
除此之外,可以通过`org.springframework.web.reactive.function.client.DefaultWebClientBuilder#defaultRequest`方法为`webClient`注册一个callback回调该回调可为所有请求插入attribute。