程序包 cn.taketoday.web
类 WebContentGenerator
java.lang.Object
cn.taketoday.context.support.ApplicationObjectSupport
cn.taketoday.web.WebContentGenerator
- 所有已实现的接口:
cn.taketoday.beans.factory.Aware,cn.taketoday.context.ApplicationContextAware
- 直接已知子类:
AbstractController,AbstractHandlerMethodAdapter,ResourceHttpRequestHandler,WebContentInterceptor
public abstract class WebContentGenerator
extends cn.taketoday.context.support.ApplicationObjectSupport
Convenient superclass for any kind of web content generator
Supports HTTP cache control options. The usage of corresponding HTTP
headers can be controlled via the "cacheSeconds"
and "cacheControl" properties.
- 从以下版本开始:
- 4.0 2022/1/29 10:25
- 作者:
- Rod Johnson, Juergen Hoeller, Brian Clozel, Rossen Stoyanchev, Harry Yang
- 另请参阅:
-
字段概要
字段修饰符和类型字段说明private Stringprivate CacheControlprivate intprotected static final Stringprivate static final Stringprivate static final Stringstatic final StringHTTP method "GET".static final StringHTTP method "HEAD".static final StringHTTP method "POST".private booleanSet of supported HTTP methods.private String[]从类继承的字段 cn.taketoday.context.support.ApplicationObjectSupport
applicationContext, log, messageSourceAccessor -
构造器概要
构造器构造器说明Create a new WebContentGenerator which supports HTTP methods GET, HEAD and POST by default.WebContentGenerator(boolean restrictDefaultSupportedMethods) Create a new WebContentGenerator.WebContentGenerator(String... supportedMethods) Create a new WebContentGenerator. -
方法概要
修饰符和类型方法说明protected final voidapplyCacheControl(RequestContext response, CacheControl cacheControl) Set the HTTP Cache-Control header according to the given settings.protected final voidapplyCacheSeconds(RequestContext 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.protected final voidcheckRequest(RequestContext request) Check the given request for supported methods and a required session, if any.protected StringReturn the "Allow" header value to use in response to an HTTP OPTIONS request based on the configuredsupported methodsalso automatically adding "OPTIONS" to the list even if not present as a supported method.final CacheControlGet theCacheControlinstance that builds the Cache-Control HTTP response header.final intReturn the number of seconds that content is cached.final String[]Return the HTTP methods that this content generator supports.final String[]Return the configured request header names for the "Vary" response header.private Collection<String>getVaryRequestHeadersToAdd(RequestContext response, String[] varyByRequestHeaders) private voidfinal booleanReturn whether a session is required to handle requests.protected final voidprepareResponse(RequestContext response) Prepare the given response according to the settings of this generator.final voidsetCacheControl(CacheControl cacheControl) Set theCacheControlinstance to build the Cache-Control HTTP response header.final voidsetCacheSeconds(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 contentfinal voidsetRequireSession(boolean requireSession) Set whether a session should be required to handle requests.final voidsetSupportedMethods(String... methods) Set the HTTP methods that this content generator should support.final voidsetVaryByRequestHeaders(String... varyByRequestHeaders) Configure one or more request header names (e.g.从类继承的方法 cn.taketoday.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, initApplicationContext, isContextRequired, obtainApplicationContext, requiredContextClass, setApplicationContext, unwrapContext, unwrapFactory
-
字段详细资料
-
METHOD_GET
HTTP method "GET".- 另请参阅:
-
METHOD_HEAD
HTTP method "HEAD".- 另请参阅:
-
METHOD_POST
HTTP method "POST".- 另请参阅:
-
HEADER_PRAGMA
- 另请参阅:
-
HEADER_EXPIRES
- 另请参阅:
-
HEADER_CACHE_CONTROL
- 另请参阅:
-
supportedMethods
Set of supported HTTP methods. -
allowHeader
-
requireSession
private boolean requireSession -
cacheControl
-
cacheSeconds
private int cacheSeconds -
varyByRequestHeaders
-
-
构造器详细资料
-
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-trueif this generator should support HTTP methods GET, HEAD and POST by default, orfalseif it should be unrestricted
-
WebContentGenerator
Create a new WebContentGenerator.- 参数:
supportedMethods- the supported HTTP methods for this content generator
-
-
方法详细资料
-
setSupportedMethods
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.
-
getSupportedMethods
Return the HTTP methods that this content generator supports. -
initAllowHeader
private void initAllowHeader() -
getAllowHeader
Return the "Allow" header value to use in response to an HTTP OPTIONS request based on the configuredsupported methodsalso 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 tocheckRequest(RequestContext). -
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. -
setCacheControl
Set theCacheControlinstance to build the Cache-Control HTTP response header. -
getCacheControl
Get theCacheControlinstance that builds the Cache-Control HTTP response header. -
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
CacheControlshould be used. -
getCacheSeconds
public final int getCacheSeconds()Return the number of seconds that content is cached. -
setVaryByRequestHeaders
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
-
getVaryByRequestHeaders
Return the configured request header names for the "Vary" response header. -
checkRequest
Check the given request for supported methods and a required session, if any.- 参数:
request- current HTTP request
-
prepareResponse
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
-
applyCacheControl
Set the HTTP Cache-Control header according to the given settings.- 参数:
response- current HTTP responsecacheControl- the pre-configured cache control settings
-
applyCacheSeconds
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 responsecacheSeconds- positive number of seconds into the future that the response should be cacheable for, 0 to prevent caching
-
getVaryRequestHeadersToAdd
private Collection<String> getVaryRequestHeadersToAdd(RequestContext response, String[] varyByRequestHeaders)
-