org.springframework.web.reactive.function.server

Interface ServerResponse.HeadersBuilder<B extends ServerResponse.HeadersBuilder<B>>

  • Type Parameters:
    B - the builder subclass
    All Known Subinterfaces:
    ServerResponse.BodyBuilder
    Enclosing interface:
    ServerResponse


    public static interface ServerResponse.HeadersBuilder<B extends ServerResponse.HeadersBuilder<B>>
    Defines a builder that adds headers to the response.
    • 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.
      B allow(java.util.Set<HttpMethod> allowedMethods)
      Set the set of allowed HTTP methods, as specified by the Allow header.
      reactor.core.publisher.Mono<ServerResponse> build()
      Build the response entity with no body.
      reactor.core.publisher.Mono<ServerResponse> build(java.util.function.BiFunction<ServerWebExchange,ServerResponse.Context,reactor.core.publisher.Mono<java.lang.Void>> writeFunction)
      Build the response entity with a custom writer function.
      reactor.core.publisher.Mono<ServerResponse> build(org.reactivestreams.Publisher<java.lang.Void> voidPublisher)
      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 cookie(ResponseCookie cookie)
      Add the given cookie to the response.
      B cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,ResponseCookie>> cookiesConsumer)
      Manipulate this response's cookies with the given consumer.
      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 header value(s) under the given name.
      B headers(java.util.function.Consumer<HttpHeaders> headersConsumer)
      Manipulate this response's headers with the given consumer.
      B lastModified(java.time.ZonedDateTime 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 header value(s) under the given name.
        Parameters:
        headerName - the header name
        headerValues - the header value(s)
        Returns:
        this builder
        See Also:
        HttpHeaders.add(String, String)
      • headers

        B headers(java.util.function.Consumer<HttpHeaders> headersConsumer)
        Manipulate this response'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 other HttpHeaders methods.
        Parameters:
        headersConsumer - a function that consumes the HttpHeaders
        Returns:
        this builder
      • cookie

        B cookie(ResponseCookie cookie)
        Add the given cookie to the response.
        Parameters:
        cookie - the cookie to add
        Returns:
        this builder
      • cookies

        B cookies(java.util.function.Consumer<MultiValueMap<java.lang.String,ResponseCookie>> cookiesConsumer)
        Manipulate this response's cookies with the given consumer. The cookies provided to the consumer are "live", so that the consumer can be used to overwrite existing cookies, remove cookies, or use any of the other MultiValueMap methods.
        Parameters:
        cookiesConsumer - a function that consumes the cookies
        Returns:
        this builder
      • 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(java.time.ZonedDateTime lastModified)
        Set the time the resource was last changed, as specified by the Last-Modified header.
        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
        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
        Returns:
        this builder
      • build

        reactor.core.publisher.Mono<ServerResponse> build()
        Build the response entity with no body.
      • build

        reactor.core.publisher.Mono<ServerResponse> build(org.reactivestreams.Publisher<java.lang.Void> voidPublisher)
        Build the response entity with no body. The response will be committed when the given voidPublisher completes.
        Parameters:
        voidPublisher - publisher publisher to indicate when the response should be committed