@@ -70,6 +70,8 @@ public final class HttpRequestValues {
70
70
71
71
private final MultiValueMap <String , String > cookies ;
72
72
73
+ private final Map <String , Object > attributes ;
74
+
73
75
@ Nullable
74
76
private final Object bodyValue ;
75
77
@@ -82,7 +84,7 @@ public final class HttpRequestValues {
82
84
83
85
private HttpRequestValues (HttpMethod httpMethod ,
84
86
@ Nullable URI uri , @ Nullable String uriTemplate , Map <String , String > uriVariables ,
85
- HttpHeaders headers , MultiValueMap <String , String > cookies ,
87
+ HttpHeaders headers , MultiValueMap <String , String > cookies , Map < String , Object > attributes ,
86
88
@ Nullable Object bodyValue ,
87
89
@ Nullable Publisher <?> body , @ Nullable ParameterizedTypeReference <?> bodyElementType ) {
88
90
@@ -94,6 +96,7 @@ private HttpRequestValues(HttpMethod httpMethod,
94
96
this .uriVariables = uriVariables ;
95
97
this .headers = headers ;
96
98
this .cookies = cookies ;
99
+ this .attributes = attributes ;
97
100
this .bodyValue = bodyValue ;
98
101
this .body = body ;
99
102
this .bodyElementType = bodyElementType ;
@@ -142,12 +145,19 @@ public HttpHeaders getHeaders() {
142
145
}
143
146
144
147
/**
145
- * Return the cookies for the request, if any .
148
+ * Return the cookies for the request, or an empty map .
146
149
*/
147
150
public MultiValueMap <String , String > getCookies () {
148
151
return this .cookies ;
149
152
}
150
153
154
+ /**
155
+ * Return the attributes associated with the request, or an empty map.
156
+ */
157
+ public Map <String , Object > getAttributes () {
158
+ return this .attributes ;
159
+ }
160
+
151
161
/**
152
162
* Return the request body as a value to be serialized, if set.
153
163
* <p>This is mutually exclusive with {@link #getBody()}.
@@ -209,6 +219,9 @@ public final static class Builder {
209
219
@ Nullable
210
220
private MultiValueMap <String , String > requestParams ;
211
221
222
+ @ Nullable
223
+ private Map <String , Object > attributes ;
224
+
212
225
@ Nullable
213
226
private Object bodyValue ;
214
227
@@ -325,6 +338,17 @@ public Builder addRequestParameter(String name, String... values) {
325
338
return this ;
326
339
}
327
340
341
+ /**
342
+ * Configure an attribute to associate with the request.
343
+ * @param name the attribute name
344
+ * @param value the attribute value
345
+ */
346
+ public Builder addAttribute (String name , Object value ) {
347
+ this .attributes = (this .attributes != null ? this .attributes : new HashMap <>());
348
+ this .attributes .put (name , value );
349
+ return this ;
350
+ }
351
+
328
352
/**
329
353
* Set the request body as a concrete value to be serialized.
330
354
* <p>This is mutually exclusive with, and resets any previously set
@@ -388,9 +412,12 @@ else if (uri != null) {
388
412
MultiValueMap <String , String > cookies = (this .cookies != null ?
389
413
new LinkedMultiValueMap <>(this .cookies ) : EMPTY_COOKIES_MAP );
390
414
415
+ Map <String , Object > attributes = (this .attributes != null ?
416
+ new HashMap <>(this .attributes ) : Collections .emptyMap ());
417
+
391
418
return new HttpRequestValues (
392
- this .httpMethod , uri , uriTemplate , uriVars , headers , cookies , bodyValue ,
393
- this .body , this .bodyElementType );
419
+ this .httpMethod , uri , uriTemplate , uriVars , headers , cookies , attributes ,
420
+ bodyValue , this .body , this .bodyElementType );
394
421
}
395
422
396
423
private String appendQueryParams (
0 commit comments