Package org.springframework.http
Interface ResponseEntity.HeadersBuilder<B extends ResponseEntity.HeadersBuilder<B>>
- Type Parameters:
B- the builder subclass
- All Known Subinterfaces:
ResponseEntity.BodyBuilder
- Enclosing class:
- ResponseEntity<T>
public static interface ResponseEntity.HeadersBuilder<B extends ResponseEntity.HeadersBuilder<B>>
Defines a builder that adds headers to the response entity.- Since:
- 4.1
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Ballow(HttpMethod... allowedMethods)Set the set of allowedHTTP methods, as specified by theAllowheader.<T> ResponseEntity<T>build()Build the response entity with no body.BcacheControl(CacheControl cacheControl)Set the caching directives for the resource, as specified by the HTTP 1.1Cache-Controlheader.BeTag(String etag)Set the entity tag of the body, as specified by theETagheader.Bheader(String headerName, String... headerValues)Add the given, single header value under the given name.Bheaders(Consumer<HttpHeaders> headersConsumer)Manipulate this entity's headers with the given consumer.Bheaders(HttpHeaders headers)Copy the given headers into the entity's headers map.BlastModified(long lastModified)Set the time the resource was last changed, as specified by theLast-Modifiedheader.BlastModified(Instant lastModified)Set the time the resource was last changed, as specified by theLast-Modifiedheader.BlastModified(ZonedDateTime lastModified)Set the time the resource was last changed, as specified by theLast-Modifiedheader.Blocation(URI location)Set the location of a resource, as specified by theLocationheader.BvaryBy(String... requestHeaders)Configure one or more request header names (e.g.
Method Detail
header
B header(String headerName, String... headerValues)
Add the given, single header value under the given name.- Parameters:
headerName- the header nameheaderValues- the header value(s)- Returns:
- this builder
- See Also:
HttpHeaders.add(String, String)
headers
B headers(@Nullable HttpHeaders headers)
Copy the given headers into the entity's headers map.- Parameters:
headers- the existing HttpHeaders to copy from- Returns:
- this builder
- Since:
- 4.1.2
- See Also:
HttpHeaders.add(String, String)
headers
B headers(Consumer<HttpHeaders> headersConsumer)
Manipulate this entity's headers with the given consumer. The headers provided to the consumer are "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the otherHttpHeadersmethods.- Parameters:
headersConsumer- a function that consumes theHttpHeaders- Returns:
- this builder
- Since:
- 5.2
allow
B allow(HttpMethod... allowedMethods)
Set the set of allowedHTTP methods, as specified by theAllowheader.- Parameters:
allowedMethods- the allowed methods- Returns:
- this builder
- See Also:
HttpHeaders.setAllow(Set)
eTag
B eTag(String etag)
Set the entity tag of the body, as specified by theETagheader.- Parameters:
etag- the new entity tag- Returns:
- this builder
- See Also:
HttpHeaders.setETag(String)
lastModified
B lastModified(ZonedDateTime lastModified)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.- Parameters:
lastModified- the last modified date- Returns:
- this builder
- Since:
- 5.1.4
- See Also:
HttpHeaders.setLastModified(ZonedDateTime)
lastModified
B lastModified(Instant lastModified)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.- Parameters:
lastModified- the last modified date- Returns:
- this builder
- Since:
- 5.1.4
- See Also:
HttpHeaders.setLastModified(Instant)
lastModified
B lastModified(long lastModified)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.The date should be specified as the number of milliseconds since January 1, 1970 GMT.
- Parameters:
lastModified- the last modified date- Returns:
- this builder
- See Also:
HttpHeaders.setLastModified(long)
location
B location(URI location)
Set the location of a resource, as specified by theLocationheader.- Parameters:
location- the location- Returns:
- this builder
- See Also:
HttpHeaders.setLocation(URI)
cacheControl
B cacheControl(CacheControl cacheControl)
Set the caching directives for the resource, as specified by the HTTP 1.1Cache-Controlheader.A
CacheControlinstance can be built likeCacheControl.maxAge(3600).cachePublic().noTransform().- Parameters:
cacheControl- a builder for cache-related HTTP response headers- Returns:
- this builder
- Since:
- 4.2
- See Also:
- RFC-7234 Section 5.2
varyBy
B varyBy(String... requestHeaders)
Configure one or more request header names (e.g. "Accept-Language") to add to the "Vary" response header to inform clients that the response is subject to content negotiation and variances based on the value of the given request headers. The configured request header names are added only if not already present in the response "Vary" header.- Parameters:
requestHeaders- request header names- Since:
- 4.3
build
<T> ResponseEntity<T> build()
Build the response entity with no body.- Returns:
- the response entity
- See Also:
ResponseEntity.BodyBuilder.body(Object)