|
26 | 26 | import java.nio.charset.StandardCharsets; |
27 | 27 | import java.security.Principal; |
28 | 28 | import java.text.SimpleDateFormat; |
| 29 | +import java.time.ZonedDateTime; |
29 | 30 | import java.util.ArrayList; |
30 | 31 | import java.util.Arrays; |
31 | 32 | import java.util.Collection; |
|
35 | 36 | import java.util.Locale; |
36 | 37 | import java.util.Map; |
37 | 38 | import java.util.TimeZone; |
| 39 | +import java.util.function.Consumer; |
38 | 40 |
|
39 | 41 | import jakarta.servlet.ServletContext; |
40 | 42 | import jakarta.servlet.ServletRequest; |
@@ -348,6 +350,37 @@ public B accept(String... mediaTypes) { |
348 | 350 | return self(); |
349 | 351 | } |
350 | 352 |
|
| 353 | + /** |
| 354 | + * Set the list of acceptable {@linkplain Charset charsets}, as specified |
| 355 | + * by the {@code Accept-Charset} header. |
| 356 | + * @param acceptableCharsets the acceptable charsets |
| 357 | + * @since 7.0 |
| 358 | + */ |
| 359 | + public B acceptCharset(Charset... acceptableCharsets) { |
| 360 | + this.headers.setAcceptCharset(Arrays.asList(acceptableCharsets)); |
| 361 | + return self(); |
| 362 | + } |
| 363 | + |
| 364 | + /** |
| 365 | + * Set the value of the {@code If-Modified-Since} header. |
| 366 | + * @param ifModifiedSince the new value of the header |
| 367 | + * @since 7.0 |
| 368 | + */ |
| 369 | + public B ifModifiedSince(ZonedDateTime ifModifiedSince) { |
| 370 | + this.headers.setIfModifiedSince(ifModifiedSince); |
| 371 | + return self(); |
| 372 | + } |
| 373 | + |
| 374 | + /** |
| 375 | + * Set the values of the {@code If-None-Match} header. |
| 376 | + * @param ifNoneMatches the new value of the header |
| 377 | + * @since 7.0 |
| 378 | + */ |
| 379 | + public B ifNoneMatch(String... ifNoneMatches) { |
| 380 | + this.headers.setIfNoneMatch(Arrays.asList(ifNoneMatches)); |
| 381 | + return self(); |
| 382 | + } |
| 383 | + |
351 | 384 | /** |
352 | 385 | * Add a header to the request. Values are always added. |
353 | 386 | * @param name the header name |
@@ -386,6 +419,18 @@ public B headers(HttpHeaders httpHeaders) { |
386 | 419 | return self(); |
387 | 420 | } |
388 | 421 |
|
| 422 | + /** |
| 423 | + * Provides access to every header declared so far with the possibility |
| 424 | + * to add, replace, or remove values. |
| 425 | + * @param headersConsumer the consumer to provide access to |
| 426 | + * @return this builder |
| 427 | + * @since 7.0 |
| 428 | + */ |
| 429 | + public B headers(Consumer<HttpHeaders> headersConsumer) { |
| 430 | + headersConsumer.accept(this.headers); |
| 431 | + return self(); |
| 432 | + } |
| 433 | + |
389 | 434 | /** |
390 | 435 | * Add a request parameter to {@link MockHttpServletRequest#getParameterMap()}. |
391 | 436 | * <p>In the Servlet API, a request parameter may be parsed from the query |
|
0 commit comments