mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-08 08:09:09 +00:00
This commit fixes syntax errors in Java, Kotlin, and XML examples in the reference manual, such as Java syntax in Kotlin examples, unbalanced braces and parentheses, and unclosed XML elements. Closes gh-37392
49 lines
1.2 KiB
Plaintext
49 lines
1.2 KiB
Plaintext
[[webflux-client-attributes]]
|
|
= Attributes
|
|
|
|
You can add attributes to a request. This is convenient if you want to pass information
|
|
through the filter chain and influence the behavior of filters for a given request.
|
|
For example:
|
|
|
|
[tabs]
|
|
======
|
|
Java::
|
|
+
|
|
[source,java,indent=0,subs="verbatim,quotes"]
|
|
----
|
|
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);
|
|
----
|
|
|
|
Kotlin::
|
|
+
|
|
[source,kotlin,indent=0,subs="verbatim,quotes"]
|
|
----
|
|
val client = WebClient.builder()
|
|
.filter { request, _ ->
|
|
val usr = request.attributes()["myAttribute"];
|
|
// ...
|
|
}
|
|
.build()
|
|
|
|
client.get().uri("https://example.org/")
|
|
.attribute("myAttribute", "...")
|
|
.retrieve()
|
|
.awaitBody<Unit>()
|
|
----
|
|
======
|
|
|
|
Note that you can configure a `defaultRequest` callback globally at the
|
|
`WebClient.Builder` level which lets you insert attributes into all requests,
|
|
which could be used for example in a Spring MVC application to populate
|
|
request attributes based on `ThreadLocal` data.
|