类 WebContentGenerator

    • 构造器详细资料

      • WebContentGenerator

        public WebContentGenerator()
        Create a new WebContentGenerator which supports HTTP methods GET, HEAD and POST by default.
      • WebContentGenerator

        public WebContentGenerator​(boolean restrictDefaultSupportedMethods)
        Create a new WebContentGenerator.
        参数:
        restrictDefaultSupportedMethods - true if this generator should support HTTP methods GET, HEAD and POST by default, or false if it should be unrestricted
      • WebContentGenerator

        public WebContentGenerator​(String... supportedMethods)
        Create a new WebContentGenerator.
        参数:
        supportedMethods - the supported HTTP methods for this content generator
    • 方法详细资料

      • setSupportedMethods

        public final void setSupportedMethods​(@Nullable
                                              String... methods)
        Set the HTTP methods that this content generator should support.

        Default is GET, HEAD and POST for simple form controller types; unrestricted for general controllers and interceptors.

      • getAllowHeader

        @Nullable
        protected String getAllowHeader()
        Return the "Allow" header value to use in response to an HTTP OPTIONS request based on the configured supported methods also automatically adding "OPTIONS" to the list even if not present as a supported method. This means subclasses don't have to explicitly list "OPTIONS" as a supported method as long as HTTP OPTIONS requests are handled before making a call to checkRequest(HttpServletRequest).
        从以下版本开始:
        4.3
      • setRequireSession

        public final void setRequireSession​(boolean requireSession)
        Set whether a session should be required to handle requests.
      • isRequireSession

        public final boolean isRequireSession()
        Return whether a session is required to handle requests.
      • setCacheSeconds

        public final void setCacheSeconds​(int seconds)
        Cache content for the given number of seconds, by writing cache-related HTTP headers to the response:
        • seconds == -1 (default value): no generation cache-related headers
        • seconds == 0: "Cache-Control: no-store" will prevent caching
        • seconds > 0: "Cache-Control: max-age=seconds" will ask to cache content

        For more specific needs, a custom CacheControl should be used.

        另请参阅:
        setCacheControl(org.springframework.http.CacheControl)
      • getCacheSeconds

        public final int getCacheSeconds()
        Return the number of seconds that content is cached.
      • setVaryByRequestHeaders

        public final void setVaryByRequestHeaders​(@Nullable
                                                  String... varyByRequestHeaders)
        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.
        参数:
        varyByRequestHeaders - one or more request header names
        从以下版本开始:
        4.3
      • setUseExpiresHeader

        @Deprecated
        public final void setUseExpiresHeader​(boolean useExpiresHeader)
        已过时。
        as of 4.2, since going forward, the HTTP 1.1 cache-control header will be required, with the HTTP 1.0 headers disappearing
        Set whether to use the HTTP 1.0 expires header. Default is "false", as of 4.2.

        Note: Cache headers will only get applied if caching is enabled (or explicitly prevented) for the current request.

      • setUseCacheControlHeader

        @Deprecated
        public final void setUseCacheControlHeader​(boolean useCacheControlHeader)
        已过时。
        as of 4.2, since going forward, the HTTP 1.1 cache-control header will be required, with the HTTP 1.0 headers disappearing
        Set whether to use the HTTP 1.1 cache-control header. Default is "true".

        Note: Cache headers will only get applied if caching is enabled (or explicitly prevented) for the current request.

      • checkRequest

        protected final void checkRequest​(HttpServletRequest request)
                                   throws ServletException
        Check the given request for supported methods and a required session, if any.
        参数:
        request - current HTTP request
        抛出:
        ServletException - if the request cannot be handled because a check failed
        从以下版本开始:
        4.2
      • prepareResponse

        protected final void prepareResponse​(HttpServletResponse response)
        Prepare the given response according to the settings of this generator. Applies the number of cache seconds specified for this generator.
        参数:
        response - current HTTP response
        从以下版本开始:
        4.2
      • applyCacheControl

        protected final void applyCacheControl​(HttpServletResponse response,
                                               CacheControl cacheControl)
        Set the HTTP Cache-Control header according to the given settings.
        参数:
        response - current HTTP response
        cacheControl - the pre-configured cache control settings
        从以下版本开始:
        4.2
      • applyCacheSeconds

        protected final void applyCacheSeconds​(HttpServletResponse response,
                                               int cacheSeconds)
        Apply the given cache seconds and generate corresponding HTTP headers, i.e. allow caching for the given number of seconds in case of a positive value, prevent caching if given a 0 value, do nothing else. Does not tell the browser to revalidate the resource.
        参数:
        response - current HTTP response
        cacheSeconds - positive number of seconds into the future that the response should be cacheable for, 0 to prevent caching
      • applyCacheSeconds

        @Deprecated
        protected final void applyCacheSeconds​(HttpServletResponse response,
                                               int cacheSeconds,
                                               boolean mustRevalidate)
        Apply the given cache seconds and generate respective HTTP headers.

        That is, allow caching for the given number of seconds in the case of a positive value, prevent caching if given a 0 value, else do nothing (i.e. leave caching to the client).

        参数:
        response - the current HTTP response
        cacheSeconds - the (positive) number of seconds into the future that the response should be cacheable for; 0 to prevent caching; and a negative value to leave caching to the client.
        mustRevalidate - whether the client should revalidate the resource (typically only necessary for controllers with last-modified support)