Class HeaderAssertions

java.lang.Object
org.springframework.test.web.reactive.server.HeaderAssertions

public class HeaderAssertions extends Object
Assertions on headers of the response.
Since:
5.0
Author:
Rossen Stoyanchev, Brian Clozel, Sam Brannen
See Also:
  • Method Details

    • valueEquals

      public WebTestClient.ResponseSpec valueEquals(String headerName, String... values)
      Expect a header with the given name to match the specified values.
    • valueEquals

      public WebTestClient.ResponseSpec valueEquals(String headerName, long value)
      Expect a header with the given name to match the given long value.
      Since:
      5.3
    • valueEqualsDate

      public WebTestClient.ResponseSpec valueEqualsDate(String headerName, long value)
      Expect a header with the given name to match the specified long value parsed into a date using the preferred date format described in RFC 7231.

      An AssertionError is thrown if the response does not contain the specified header, or if the supplied value does not match the primary header value.

      Since:
      5.3
    • valueMatches

      public WebTestClient.ResponseSpec valueMatches(String name, String pattern)
      Match the first value of the response header with a regex.
      Parameters:
      name - the header name
      pattern - the regex pattern
    • valuesMatch

      public WebTestClient.ResponseSpec valuesMatch(String name, String... patterns)
      Match all values of the response header with the given regex patterns which are applied to the values of the header in the same order. Note that the number of patterns must match the number of actual values.
      Parameters:
      name - the header name
      patterns - one or more regex patterns, one per expected value
      Since:
      5.3
    • value

      public WebTestClient.ResponseSpec value(String name, Matcher<? super String> matcher)
      Assert the first value of the response header with a Hamcrest Matcher.
      Parameters:
      name - the header name
      matcher - the matcher to use
      Since:
      5.1
    • values

      public WebTestClient.ResponseSpec values(String name, Matcher<? super Iterable<String>> matcher)
      Assert all values of the response header with a Hamcrest Matcher.
      Parameters:
      name - the header name
      matcher - the matcher to use
      Since:
      5.3
    • value

      public WebTestClient.ResponseSpec value(String name, Consumer<String> consumer)
      Consume the first value of the named response header.
      Parameters:
      name - the header name
      consumer - the consumer to use
      Since:
      5.1
    • values

      public WebTestClient.ResponseSpec values(String name, Consumer<List<String>> consumer)
      Consume all values of the named response header.
      Parameters:
      name - the header name
      consumer - the consumer to use
      Since:
      5.3
    • exists

      public WebTestClient.ResponseSpec exists(String name)
      Expect that the header with the given name is present.
      Since:
      5.0.3
    • doesNotExist

      public WebTestClient.ResponseSpec doesNotExist(String name)
      Expect that the header with the given name is not present.
    • cacheControl

      public WebTestClient.ResponseSpec cacheControl(CacheControl cacheControl)
      Expect a "Cache-Control" header with the given value.
    • contentDisposition

      public WebTestClient.ResponseSpec contentDisposition(ContentDisposition contentDisposition)
      Expect a "Content-Disposition" header with the given value.
    • contentLength

      public WebTestClient.ResponseSpec contentLength(long contentLength)
      Expect a "Content-Length" header with the given value.
    • contentType

      public WebTestClient.ResponseSpec contentType(MediaType mediaType)
      Expect a "Content-Type" header with the given value.
    • contentType

      public WebTestClient.ResponseSpec contentType(String mediaType)
      Expect a "Content-Type" header with the given value.
    • contentTypeCompatibleWith

      public WebTestClient.ResponseSpec contentTypeCompatibleWith(MediaType mediaType)
      Expect a "Content-Type" header compatible with the given value.
    • contentTypeCompatibleWith

      public WebTestClient.ResponseSpec contentTypeCompatibleWith(String mediaType)
      Expect a "Content-Type" header compatible with the given value.
    • expires

      public WebTestClient.ResponseSpec expires(long expires)
      Expect an "Expires" header with the given value.
    • lastModified

      public WebTestClient.ResponseSpec lastModified(long lastModified)
      Expect a "Last-Modified" header with the given value.
    • location

      public WebTestClient.ResponseSpec location(String location)
      Expect a "Location" header with the given value.
      Since:
      5.3