接口 ServerRequest

    • 方法详细资料

      • method

        @Nullable
        default HttpMethod method()
        Get the HTTP method.
        返回:
        the HTTP method as an HttpMethod enum value, or null if not resolvable (e.g. in case of a non-standard HTTP method)
      • methodName

        String methodName()
        Get the name of the HTTP method.
        返回:
        the HTTP method as a String
      • uri

        URI uri()
        Get the request URI.
      • uriBuilder

        UriBuilder uriBuilder()
        Get a UriBuilderComponents from the URI associated with this ServerRequest.

        Note: as of 5.1 this method ignores "Forwarded" and "X-Forwarded-*" headers that specify the client-originated address. Consider using the ForwardedHeaderFilter to extract and use, or to discard such headers.

        返回:
        a URI builder
      • body

        <T> T body​(BodyExtractor<T,​? super ServerHttpRequest> extractor)
        Extract the body with the given BodyExtractor.
        类型参数:
        T - the type of the body returned
        参数:
        extractor - the BodyExtractor that reads from the request
        返回:
        the extracted body
        另请参阅:
        body(BodyExtractor, Map)
      • bodyToMono

        <T> reactor.core.publisher.Mono<T> bodyToMono​(Class<? extends T> elementClass)
        Extract the body to a Mono.
        类型参数:
        T - the element type
        参数:
        elementClass - the class of element in the Mono
        返回:
        the body as a mono
      • bodyToMono

        <T> reactor.core.publisher.Mono<T> bodyToMono​(ParameterizedTypeReference<T> typeReference)
        Extract the body to a Mono.
        类型参数:
        T - the element type
        参数:
        typeReference - a type reference describing the expected response request type
        返回:
        a mono containing the body of the given type T
      • bodyToFlux

        <T> reactor.core.publisher.Flux<T> bodyToFlux​(Class<? extends T> elementClass)
        Extract the body to a Flux.
        类型参数:
        T - the element type
        参数:
        elementClass - the class of element in the Flux
        返回:
        the body as a flux
      • bodyToFlux

        <T> reactor.core.publisher.Flux<T> bodyToFlux​(ParameterizedTypeReference<T> typeReference)
        Extract the body to a Flux.
        类型参数:
        T - the element type
        参数:
        typeReference - a type reference describing the expected request body type
        返回:
        a flux containing the body of the given type T
      • attribute

        default Optional<Objectattribute​(String name)
        Get the request attribute value if present.
        参数:
        name - the attribute name
        返回:
        the attribute value
      • queryParam

        default Optional<StringqueryParam​(String name)
        Get the first query parameter with the given name, if present.
        参数:
        name - the parameter name
        返回:
        the parameter value
      • pathVariable

        default String pathVariable​(String name)
        Get the path variable with the given name, if present.
        参数:
        name - the variable name
        返回:
        the variable value
        抛出:
        IllegalArgumentException - if there is no path variable with the given name
      • session

        reactor.core.publisher.Mono<WebSessionsession()
        Get the web session for this request.

        Always guaranteed to return an instance either matching the session id requested by the client, or with a new session id either because the client did not specify one or because the underlying session had expired.

        Use of this method does not automatically create a session.

      • principal

        reactor.core.publisher.Mono<? extends Principalprincipal()
        Get the authenticated user for the request, if any.
      • formData

        reactor.core.publisher.Mono<MultiValueMap<String,​String>> formData()
        Get the form data from the body of the request if the Content-Type is "application/x-www-form-urlencoded" or an empty map otherwise.

        Note: calling this method causes the request body to be read and parsed in full, and the resulting MultiValueMap is cached so that this method is safe to call more than once.

      • multipartData

        reactor.core.publisher.Mono<MultiValueMap<String,​Part>> multipartData()
        Get the parts of a multipart request if the Content-Type is "multipart/form-data" or an empty map otherwise.

        Note: calling this method causes the request body to be read and parsed in full, and the resulting MultiValueMap is cached so that this method is safe to call more than once.

      • exchange

        ServerWebExchange exchange()
        Get the web exchange that this request is based on.

        Note: Manipulating the exchange directly (instead of using the methods provided on ServerRequest and ServerResponse) can lead to irregular results.

        从以下版本开始:
        5.1
      • checkNotModified

        default reactor.core.publisher.Mono<ServerResponsecheckNotModified​(Instant lastModified)
        Check whether the requested resource has been modified given the supplied last-modified timestamp (as determined by the application).

        If not modified, this method returns a response with corresponding status code and headers, otherwise an empty result.

        Typical usage:

         public Mono<ServerResponse> myHandleMethod(ServerRequest request) {
           Instant lastModified = // application-specific calculation
                 return request.checkNotModified(lastModified)
                   .switchIfEmpty(Mono.defer(() -> {
                     // further request processing, actually building content
                         return ServerResponse.ok().body(...);
                   }));
         }

        This method works with conditional GET/HEAD requests, but also with conditional POST/PUT/DELETE requests.

        Note: you can use either this #checkNotModified(Instant) method; or checkNotModified(String). If you want enforce both a strong entity tag and a Last-Modified value, as recommended by the HTTP specification, then you should use checkNotModified(Instant, String).

        参数:
        lastModified - the last-modified timestamp that the application determined for the underlying resource
        返回:
        a corresponding response if the request qualifies as not modified, or an empty result otherwise
        从以下版本开始:
        5.2.5
      • checkNotModified

        default reactor.core.publisher.Mono<ServerResponsecheckNotModified​(String etag)
        Check whether the requested resource has been modified given the supplied ETag (entity tag), as determined by the application.

        If not modified, this method returns a response with corresponding status code and headers, otherwise an empty result.

        Typical usage:

         public Mono<ServerResponse> myHandleMethod(ServerRequest request) {
           String eTag = // application-specific calculation
                 return request.checkNotModified(eTag)
                   .switchIfEmpty(Mono.defer(() -> {
                     // further request processing, actually building content
                         return ServerResponse.ok().body(...);
                   }));
         }

        This method works with conditional GET/HEAD requests, but also with conditional POST/PUT/DELETE requests.

        Note: you can use either this checkNotModified(Instant) method; or #checkNotModified(String). If you want enforce both a strong entity tag and a Last-Modified value, as recommended by the HTTP specification, then you should use checkNotModified(Instant, String).

        参数:
        etag - the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.
        返回:
        a corresponding response if the request qualifies as not modified, or an empty result otherwise
        从以下版本开始:
        5.2.5
      • checkNotModified

        default reactor.core.publisher.Mono<ServerResponsecheckNotModified​(Instant lastModified,
                                                                             String etag)
        Check whether the requested resource has been modified given the supplied ETag (entity tag) and last-modified timestamp, as determined by the application.

        If not modified, this method returns a response with corresponding status code and headers, otherwise an empty result.

        Typical usage:

         public Mono<ServerResponse> myHandleMethod(ServerRequest request) {
           Instant lastModified = // application-specific calculation
           String eTag = // application-specific calculation
                 return request.checkNotModified(lastModified, eTag)
                   .switchIfEmpty(Mono.defer(() -> {
                     // further request processing, actually building content
                         return ServerResponse.ok().body(...);
                   }));
         }

        This method works with conditional GET/HEAD requests, but also with conditional POST/PUT/DELETE requests.

        参数:
        lastModified - the last-modified timestamp that the application determined for the underlying resource
        etag - the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.
        返回:
        a corresponding response if the request qualifies as not modified, or an empty result otherwise.
        从以下版本开始:
        5.2.5
      • create

        static ServerRequest create​(ServerWebExchange exchange,
                                    List<HttpMessageReader<?>> messageReaders)
        Create a new ServerRequest based on the given ServerWebExchange and message readers.
        参数:
        exchange - the exchange
        messageReaders - the message readers
        返回:
        the created ServerRequest
      • from

        static ServerRequest.Builder from​(ServerRequest other)
        Create a builder with the message readers, method name, URI, headers, cookies, and attributes of the given request.
        参数:
        other - the request to copy the message readers, method name, URI, headers, and attributes from
        返回:
        the created builder
        从以下版本开始:
        5.1