23
23
import java .util .LinkedHashMap ;
24
24
import java .util .List ;
25
25
import java .util .Map ;
26
+ import java .util .function .Consumer ;
26
27
27
28
import org .jspecify .annotations .Nullable ;
28
29
@@ -69,7 +70,7 @@ public class HttpRequestValues {
69
70
70
71
private final MultiValueMap <String , String > cookies ;
71
72
72
- private @ Nullable Object version ;
73
+ private final @ Nullable Object version ;
73
74
74
75
private final Map <String , Object > attributes ;
75
76
@@ -353,6 +354,16 @@ public Builder addHeader(String headerName, String... headerValues) {
353
354
return this ;
354
355
}
355
356
357
+ /**
358
+ * Provide access to every header configured so far with the option to
359
+ * add, replace, or remove values.
360
+ * @since 7.0
361
+ */
362
+ public Builder configureHeaders (Consumer <HttpHeaders > consumer ) {
363
+ consumer .accept (initHeaders ());
364
+ return this ;
365
+ }
366
+
356
367
private HttpHeaders initHeaders () {
357
368
this .headers = (this .headers != null ? this .headers : new HttpHeaders ());
358
369
return this .headers ;
@@ -362,13 +373,27 @@ private HttpHeaders initHeaders() {
362
373
* Add the given cookie name and values.
363
374
*/
364
375
public Builder addCookie (String name , String ... values ) {
365
- this .cookies = (this .cookies != null ? this .cookies : new LinkedMultiValueMap <>());
366
376
for (String value : values ) {
367
- this . cookies .add (name , value );
377
+ initCookies () .add (name , value );
368
378
}
369
379
return this ;
370
380
}
371
381
382
+ /**
383
+ * Provide access to every cookie configured so far with the option to
384
+ * add, replace, or remove values.
385
+ * @since 7.0
386
+ */
387
+ public Builder configureCookies (Consumer <MultiValueMap <String , String >> consumer ) {
388
+ consumer .accept (initCookies ());
389
+ return this ;
390
+ }
391
+
392
+ private MultiValueMap <String , String > initCookies () {
393
+ this .cookies = (this .cookies != null ? this .cookies : new LinkedMultiValueMap <>());
394
+ return this .cookies ;
395
+ }
396
+
372
397
/**
373
398
* Add the given request parameter name and values.
374
399
* <p>When {@code "content-type"} is set to
@@ -377,13 +402,27 @@ public Builder addCookie(String name, String... values) {
377
402
* parameters.
378
403
*/
379
404
public Builder addRequestParameter (String name , String ... values ) {
380
- this .requestParams = (this .requestParams != null ? this .requestParams : new LinkedMultiValueMap <>());
381
405
for (String value : values ) {
382
- this . requestParams .add (name , value );
406
+ initRequestParams () .add (name , value );
383
407
}
384
408
return this ;
385
409
}
386
410
411
+ /**
412
+ * Provide access to every request parameter configured so far with the
413
+ * option to add, replace, or remove values.
414
+ * @since 7.0
415
+ */
416
+ public Builder configureRequestParams (Consumer <MultiValueMap <String , String >> consumer ) {
417
+ consumer .accept (initRequestParams ());
418
+ return this ;
419
+ }
420
+
421
+ private MultiValueMap <String , String > initRequestParams () {
422
+ this .requestParams = (this .requestParams != null ? this .requestParams : new LinkedMultiValueMap <>());
423
+ return this .requestParams ;
424
+ }
425
+
387
426
/**
388
427
* Add a part for a multipart request. The part may be:
389
428
* <ul>
@@ -420,11 +459,25 @@ public Builder setApiVersion(Object version) {
420
459
* @param value the attribute value
421
460
*/
422
461
public Builder addAttribute (String name , Object value ) {
423
- this .attributes = (this .attributes != null ? this .attributes : new HashMap <>());
424
- this .attributes .put (name , value );
462
+ initAttributes ().put (name , value );
425
463
return this ;
426
464
}
427
465
466
+ /**
467
+ * Provide access to every attribute configured so far with the option
468
+ * to add, replace, or remove values.
469
+ * @since 7.0
470
+ */
471
+ public Builder configureAttributes (Consumer <Map <String , Object >> consumer ) {
472
+ consumer .accept (initAttributes ());
473
+ return this ;
474
+ }
475
+
476
+ private Map <String , Object > initAttributes () {
477
+ this .attributes = (this .attributes != null ? this .attributes : new HashMap <>());
478
+ return this .attributes ;
479
+ }
480
+
428
481
/**
429
482
* Set the request body as an Object to be serialized.
430
483
*/
0 commit comments