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 and Description
      B allow(HttpMethod... allowedMethods)
      Set the set of allowed HTTP methods, as specified by the Allow header.
      <T> ResponseEntity<T> build()
      Build the response entity with no body.
      B cacheControl(CacheControl cacheControl)
      Set the caching directives for the resource, as specified by the HTTP 1.1 Cache-Control header.
      B eTag(java.lang.String etag)
      Set the entity tag of the body, as specified by the ETag header.
      B header(java.lang.String headerName, java.lang.String... headerValues)
      Add the given, single header value under the given name.
      B headers(HttpHeaders headers)
      Copy the given headers into the entity's headers map.
      B lastModified(long lastModified)
      Set the time the resource was last changed, as specified by the Last-Modified header.
      B location(java.net.URI location)
      Set the location of a resource, as specified by the Location header.
      B varyBy(java.lang.String... requestHeaders)
      Configure one or more request header names (e.g.
    • Method Detail

      • header

        B header(java.lang.String headerName,
                 java.lang.String... headerValues)
        Add the given, single header value under the given name.
        Parameters:
        headerName - the header name
        headerValues - the header value(s)
        Returns:
        this builder
        See Also:
        HttpHeaders.add(String, String)
      • eTag

        B eTag(java.lang.String etag)
        Set the entity tag of the body, as specified by the ETag header.
        Parameters:
        etag - the new entity tag
        Returns:
        this builder
        See Also:
        HttpHeaders.setETag(String)
      • lastModified

        B lastModified(long lastModified)
        Set the time the resource was last changed, as specified by the Last-Modified header.

        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(java.net.URI location)
        Set the location of a resource, as specified by the Location header.
        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.1 Cache-Control header.

        A CacheControl instance can be built like CacheControl.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(java.lang.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