doc: 阅读webclient文档
This commit is contained in:
@@ -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。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user