类 RequestContext
- 所有已实现的接口:
cn.taketoday.core.AttributeAccessor,cn.taketoday.core.io.InputStreamSource,cn.taketoday.core.io.OutputStreamSource,HttpInputMessage,HttpMessage,HttpRequest,Serializable
- 直接已知子类:
DecoratingRequestContext,DefaultServerRequest.CheckNotModifiedResponse,ServletRequestContext
- 从以下版本开始:
- 2.3.7
- 作者:
- TODAY 2019-06-22 15:48
- 另请参阅:
-
嵌套类概要
嵌套类 -
字段概要
字段修饰符和类型字段说明protected final cn.taketoday.context.ApplicationContextprotected AsyncWebRequestprotected BindingContextprotected Stringprotected HttpCookie[]protected Booleanprivate static final String[]Date formats as specified in the HTTP RFC.static final HttpCookie[]private static final TimeZoneprotected HttpMethodprivate Stringprotected InputStreamprotected Localeprotected PathContainerprivate HandlerMatchingMetadataprotected Stringprotected Booleanprotected MultipartRequestprotected booleanprotected OutputStreamprotected PathContainerprotected Booleanprotected Stringprotected BufferedReaderprotected Objectprivate longprotected LinkedHashMap<String,Runnable> Map from attribute name String to destruction callback Runnable.protected HttpHeadersprotected RequestPathprotected Stringprotected Stringprotected ArrayList<HttpCookie>protected HttpHeadersstatic final StringScope identifier for request scope: "request".static final StringScope identifier for session scope: "session".private static final longprotected URIprotected WebAsyncManagerprivate WebAsyncManagerFactoryprotected PrintWriter从类继承的字段 cn.taketoday.core.AttributeAccessorSupport
attributes -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private voidaddCachingResponseHeaders(String eTag, long lastModifiedTimestamp) voidaddCookie(HttpCookie cookie) Adds the specified cookie to the response.voidAdds the specified cookie to the response.binding()booleancheckNotModified(long lastModifiedTimestamp) Check whether the requested resource has been modified given the supplied last-modified timestamp (as determined by the application).booleancheckNotModified(String etag) Check whether the requested resource has been modified given the suppliedETag(entity tag), as determined by the application.booleancheckNotModified(String eTag, long lastModifiedTimestamp) Check whether the requested resource has been modified given the suppliedETag(entity tag) and last-modified timestamp, as determined by the application.protected abstract AsyncWebRequestprotected abstract MultipartRequestcreate MultipartRequestprotected abstract HttpHeaderstemplate method for create request http-headersprotected HttpHeaderscreate a new response http-headerprivate WebAsyncManagerprotected Stringprotected abstract HttpCookie[]protected abstract InputStreamprotected Localeprotected abstract Stringprotected abstract OutputStreamtemplate method for get OutputStreamprotected abstract Stringprotected BufferedReadertemplate method for get readerprotected RequestPathprotected abstract Stringprotected PrintWritertemplate method for get writerprivate booleaneTagStrongMatch(String first, String second) private booleaneTagWeakMatch(String first, String second) voidflush()Forces any content in the buffer to be written to the client.cn.taketoday.context.ApplicationContextReturn the WebApplicationContext that this request runs in.getBody()Return the body of the message as an input stream.abstract longReturns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.abstract StringReturns the MIME type of the body of the request, ornullif the type is not known.Returns the portion of the request URI that indicates the context of the request.Returns aHttpCookieobject the client sent with this request.Returns an array containing all of theCookieobjects the client sent with this request.Return the headers of this message.Return read-only "input" flash attributes from request before redirect.Return read-only "input" flash attributes from request before redirect.Retrieves the body of the request as binary data using aInputStream.Returns the preferredLocalethat the client will accept content in, based on the Accept-Language header.Return the HTTP method of the request.Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.Returns aOutputStreamsuitable for writing binary data in the response.getParameter(String name) Returns the value of a request parameter as aString, ornullif the parameter does not exist.Returns anIteratorofStringobjects containing the names of the parameters contained in this request.Returns a java.util.Map of the parameters of this request.String[]getParameters(String name) Returns an array ofStringobjects containing all of the values the given request parameter has, ornullif the parameter does not exist.protected static intReturns the query string that is contained in the request URL after the path.Retrieves the body of the request as character data using aBufferedReader.abstract StringReturns the Internet Protocol (IP) address of the client or last proxy that sent the request.Obtain a unique identifier string for this request.final longGet this request processing time millisabstract longGet start handling this request time millisReturns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.Returns the content type used for the MIME body sent in this response.abstract StringReturns the name of the scheme used to make this request, for example,http,https, orftp.abstract StringReturns the host name of the server to which the request was sent.abstract intReturns the port number to which the request was sent.abstract intGets the current status code of this response.getURI()Return the URI of the request (including a query string if any, but only if it is well-formed for a URI representation).Returns aPrintWriterobject that can send character text to the client.booleanbooleanprotected StringinitId()Obtain the request id to use, ornullin which case the Object identity of this request instance is used.abstract booleanReturns a boolean indicating if the response has been committed.booleanWhether the selected handler for the current request chose to handle the request asynchronously.booleanReturnstrueif the request is a valid CORS one by checkingOriginheader presence and ensuring that origins are different.booleanbooleanbooleanReturnstrueif the request is a valid CORS pre-flight one by checking {code OPTIONS} method withOriginandAccess-Control-Request-Methodheaders presence.private booleanmatchRequestedETags(List<String> requestedETags, String eTag, boolean weakCompare) voidmergeToResponse(HttpHeaders headers) merge headers to response http-headersabstract <T> TNative request eg: HttpServletRequestprivate StringpadEtagIfNecessary(String etag) private longparseDateHeader(String headerName) private longparseDateValue(String headerValue) protected voidpostGetParameters(cn.taketoday.util.MultiValueMap<String, String> parameters) protected voidpostRequestCompleted(Throwable notHandled) final voidregisterRequestDestructionCallback(Runnable callback) Register the given callback as to be executed after request completion.final voidregisterRequestDestructionCallback(String name, Runnable callback) Register the given callback as to be executed after request completion.removeCookie(String name) remove the specified cookie from responsefinal voidRemove the request destruction callback for the specified attribute, if any.voidSignal that the request has been completed.voidrequestCompleted(Throwable notHandled) Signal that the request has been completed.Get request HTTP headersvoidreset()Clears any data that exists in the buffer as well as the status code, headers.Get request HTTP headersabstract voidsendError(int sc) Sends an error response to the client using the specified status code and clears the buffer.abstract voidSends an error response to the client using the specified status and clears the buffer.voidsendError(HttpStatusCode code) Sends an error response to the client using the specified status code and clears the buffer.voidsendError(HttpStatusCode code, String msg) Sends an error response to the client using the specified status and clears the buffer.abstract voidsendRedirect(String location) Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.voidsetBinding(BindingContext bindingContext) voidsetContentLength(long length) Sets the length of the content body in the response , this method sets the HTTP Content-Length header.voidsetContentType(MediaType contentType) Sets the content type of the response being sent to the client, if the response has not been committed yet.voidsetContentType(String contentType) Sets the content type of the response being sent to the client, if the response has not been committed yet.voidsetMatchingMetadata(HandlerMatchingMetadata handlerMatchingMetadata) abstract voidsetStatus(int sc) Sets the status code for this response.voidsetStatus(HttpStatusCode status) Sets the status code and message for this response.voidsetWebAsyncManagerFactory(WebAsyncManagerFactory webAsyncManagerFactory) toString()abstract <T> TunwrapRequest(Class<T> requestClass) private voidupdateResponseIdempotent(String eTag, long lastModifiedTimestamp) private voidupdateResponseStateChanging(String eTag, long lastModifiedTimestamp) private booleanvalidateIfMatch(String eTag) private voidvalidateIfModifiedSince(long lastModifiedTimestamp) private booleanvalidateIfNoneMatch(String eTag) private booleanvalidateIfUnmodifiedSince(long lastModifiedTimestamp) voidwrite headers to response从类继承的方法 cn.taketoday.core.AttributeAccessorSupport
attributeNames, clearAttributes, computeAttribute, copyAttributesFrom, createAttributes, equals, getAttribute, getAttributeNames, getAttributes, hasAttribute, hasAttributes, hashCode, removeAttribute, setAttribute从接口继承的方法 cn.taketoday.core.AttributeAccessor
attributeNames, clearAttributes, computeAttribute, copyAttributesFrom, getAttribute, getAttributeNames, getAttributes, hasAttribute, hasAttributes, removeAttribute, setAttribute从接口继承的方法 cn.taketoday.core.io.InputStreamSource
getReader, readableChannel从接口继承的方法 cn.taketoday.core.io.OutputStreamSource
writableChannel
-
字段详细资料
-
serialVersionUID
private static final long serialVersionUID- 另请参阅:
-
SCOPE_REQUEST
Scope identifier for request scope: "request". Supported in addition to the standard scopes "singleton" and "prototype".- 另请参阅:
-
SCOPE_SESSION
Scope identifier for session scope: "session". Supported in addition to the standard scopes "singleton" and "prototype".- 另请参阅:
-
SAFE_METHODS
-
DATE_FORMATS
Date formats as specified in the HTTP RFC. -
GMT
-
EMPTY_COOKIES
-
contextPath
-
cookies
-
writer
-
reader
-
inputStream
-
outputStream
-
requestHeaders
- 从以下版本开始:
- 3.0
-
responseHeaders
- 从以下版本开始:
- 3.0
-
method
- 从以下版本开始:
- 3.0
-
requestURI
- 从以下版本开始:
- 3.0
-
requestPath
- 从以下版本开始:
- 4.0
-
parameters
- 从以下版本开始:
- 3.0
-
queryString
- 从以下版本开始:
- 3.0
-
responseCookies
- 从以下版本开始:
- 3.0
-
uri
- 从以下版本开始:
- 4.0
-
httpMethod
- 从以下版本开始:
- 4.0
-
lookupPath
- 从以下版本开始:
- 4.0
-
pathWithinApplication
- 从以下版本开始:
- 4.0
-
locale
- 从以下版本开始:
- 4.0
-
responseContentType
- 从以下版本开始:
- 4.0
-
applicationContext
protected final cn.taketoday.context.ApplicationContext applicationContext- 从以下版本开始:
- 4.0
-
multipartRequest
- 从以下版本开始:
- 4.0
-
asyncWebRequest
- 从以下版本开始:
- 4.0
-
webAsyncManager
-
notModified
protected boolean notModified -
matchingMetadata
-
bindingContext
-
redirectModel
-
multipartFlag
-
preFlightRequestFlag
-
corsRequestFlag
-
requestDestructionCallbacks
Map from attribute name String to destruction callback Runnable. @since 4.0 -
requestCompletedTimeMillis
private long requestCompletedTimeMillis -
id
-
webAsyncManagerFactory
-
-
构造器详细资料
-
RequestContext
protected RequestContext(cn.taketoday.context.ApplicationContext context)
-
-
方法详细资料
-
getApplicationContext
public cn.taketoday.context.ApplicationContext getApplicationContext()Return the WebApplicationContext that this request runs in.- 从以下版本开始:
- 4.0
-
getRequestTimeMillis
public abstract long getRequestTimeMillis()Get start handling this request time millis- 返回:
- start handling this request time millis
- 从以下版本开始:
- 4.0
-
getRequestProcessingTime
public final long getRequestProcessingTime()Get this request processing time millis- 返回:
- this request processing time millis
- 从以下版本开始:
- 4.0
-
getRequestId
Obtain a unique identifier string for this request.There is no defined format for this string. The format is implementation dependent.
- 返回:
- A unique identifier for the request
- 从以下版本开始:
- 4.0
-
initId
Obtain the request id to use, ornullin which case the Object identity of this request instance is used. -
getScheme
Returns the name of the scheme used to make this request, for example,http,https, orftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.- 返回:
- a
Stringcontaining the name of the scheme used to make this request - 从以下版本开始:
- 3.0.1
-
getServerName
Returns the host name of the server to which the request was sent. It is the value of the part before ":" in theHostheader value, if any, or the resolved server name, or the server IP address.- 返回:
- a
Stringcontaining the name of the server - 从以下版本开始:
- 4.0
-
getServerPort
public abstract int getServerPort()Returns the port number to which the request was sent. It is the value of the part after ":" in theHostheader value, if any, or the server port where the client connection was accepted on.- 返回:
- an integer specifying the port number
- 从以下版本开始:
- 4.0
-
getContextPath
Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "" character but does not end with a "" character. The container does not decode this string.- 返回:
- a
Stringspecifying the portion of the request URI that indicates the context of the request
-
doGetContextPath
-
getURI
从接口复制的说明:HttpRequestReturn the URI of the request (including a query string if any, but only if it is well-formed for a URI representation).- 指定者:
getURI在接口中HttpRequest- 返回:
- the URI of the request (never
null)
-
getRequestURI
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. The web container does not decode this String. For example:First line of HTTP request Returned Value POST /some/path.html HTTP/1.1 /some/path.html GET http://foo.bar/a.html HTTP/1.0 /a.html HEAD /xyz?a=b HTTP/1.1 /xyz - 返回:
- a
Stringcontaining the part of the URL from the protocol name up to the query string
-
getRequestPath
- 另请参阅:
-
doGetRequestPath
-
getLookupPath
- 从以下版本开始:
- 4.0
-
setMatchingMetadata
-
getMatchingMetadata
-
matchingMetadata
- 抛出:
IllegalStateException- if HandlerMatchingMetadata is not set- 从以下版本开始:
- 4.0
-
hasMatchingMetadata
public boolean hasMatchingMetadata() -
doGetRequestURI
-
getRequestURL
The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.- 返回:
- A URL
-
getQueryString
Returns the query string that is contained in the request URL after the path. This method returnsnullif the URL does not have a query string. Same as the value of the CGI variable QUERY_STRING.- 返回:
- a
Stringcontaining the query string ornullif the URL contains no query string. The value is not decoded by the container.
-
doGetQueryString
-
getCookies
Returns an array containing all of theCookieobjects the client sent with this request. This method returnsnullif no cookies were sent.- 返回:
- an array of all the
Cookiesincluded with this request, orEMPTY_COOKIESif the request has no cookies
-
doGetCookies
- 返回:
- an array of all the Cookies included with this request,or
EMPTY_COOKIESif the request has no cookies
-
getCookie
Returns aHttpCookieobject the client sent with this request. This method returnsnullif no target cookie were sent.- 参数:
name- Cookie name- 返回:
- a
HttpCookieobject the client sent with this request. This method returnsnullif no target cookie were sent. - 从以下版本开始:
- 2.3.7
-
addCookie
Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.- 参数:
cookie- the Cookie to return to the client
-
addCookie
Adds the specified cookie to the response. This method can be called multiple times to set more than one cookie.- 参数:
name- the Cookie name to return to the clientvalue- the Cookie value to return to the client
-
removeCookie
remove the specified cookie from response- 参数:
name- cookie name- 返回:
- removed cookie
-
responseCookies
-
getParameters
Returns a java.util.Map of the parameters of this request.Request parameters are extra information sent with the request. Parameters are contained in the query string or posted form data.
- 返回:
- java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.
-
doGetParameters
-
postGetParameters
-
getParameterNames
Returns anIteratorofStringobjects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an emptyIterator.- 返回:
- an
IteratorofStringobjects, eachStringcontaining the name of a request parameter; or an emptyIteratorif the request has no parameters
-
getParameters
Returns an array ofStringobjects containing all of the values the given request parameter has, ornullif the parameter does not exist.If the parameter has a single value, the array has a length of 1.
- 参数:
name- aStringcontaining the name of the parameter whose value is requested- 返回:
- an array of
Stringobjects containing the parameter's values - 另请参阅:
-
getParameter
Returns the value of a request parameter as aString, ornullif the parameter does not exist. Request parameters are extra information sent with the request. Parameters are contained in the query string or posted form data.You should only use this method when you are sure the parameter has only one value. If the parameter might have more than one value, use
getParameters(String).If you use this method with a multivalued parameter, the value returned is equal to the first value in the array returned by
parameters(String).If the parameter data was sent in the request body, such as occurs with an HTTP POST request, then reading the body directly via
getInputStream()orgetReader()can interfere with the execution of this method.- 参数:
name- aStringspecifying the name of the parameter- 返回:
- a
Stringrepresenting the single value of the parameter - 另请参阅:
-
getMethodValue
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.- 指定者:
getMethodValue在接口中HttpRequest- 返回:
- a
Stringspecifying the name of the method with which this request was made - 另请参阅:
-
getMethod
从接口复制的说明:HttpRequestReturn the HTTP method of the request.- 指定者:
getMethod在接口中HttpRequest- 返回:
- the HTTP method as an HttpMethod value
- 另请参阅:
-
doGetMethod
-
getRemoteAddress
Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.- 返回:
- a
Stringcontaining the IP address of the client that sent the request
-
getContentLength
public abstract long getContentLength()Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.- 返回:
- a long containing the length of the request body or -1L if the length is not known
-
getBody
从接口复制的说明:HttpInputMessageReturn the body of the message as an input stream.- 指定者:
getBody在接口中HttpInputMessage- 返回:
- the input stream body (never
null) - 抛出:
IOException- in case of I/O errors
-
getHeaders
从接口复制的说明:HttpMessageReturn the headers of this message.- 指定者:
getHeaders在接口中HttpMessage- 返回:
- a corresponding HttpHeaders object (never
null)
-
getInputStream
Retrieves the body of the request as binary data using aInputStream. Either this method orgetReader()may be called to read the body, not both.- 指定者:
getInputStream在接口中cn.taketoday.core.io.InputStreamSource- 返回:
- a
InputStreamobject containing the body of the request - 抛出:
IllegalStateException- For Servlet Environment if thegetReader()method has already been called for this requestIOException- if an input or output exception occurred
-
doGetInputStream
- 抛出:
IOException
-
getReader
Retrieves the body of the request as character data using aBufferedReader. The reader translates the character data according to the character encoding used on the body. Either this method orgetInputStream()may be called to read the body, not both.- 指定者:
getReader在接口中cn.taketoday.core.io.InputStreamSource- 返回:
- a
BufferedReadercontaining the body of the request - 抛出:
IllegalStateException- For Servlet Environment ifgetInputStream()method has been called on this requestIOException- if an input or output exception occurred- 另请参阅:
-
doGetReader
template method for get reader- 抛出:
IOException
-
isMultipart
public boolean isMultipart()- 返回:
- return whether this request is multipart
- 从以下版本开始:
- 4.0
-
getMultipartRequest
- 从以下版本开始:
- 4.0
- 另请参阅:
-
createMultipartRequest
create MultipartRequest- 从以下版本开始:
- 4.0
-
isConcurrentHandlingStarted
public boolean isConcurrentHandlingStarted()Whether the selected handler for the current request chose to handle the request asynchronously. A return value of "true" indicates concurrent handling is under way and the response will remain open. A return value of "false" means concurrent handling was either not started or possibly that it has completed and the request was dispatched for further processing of the concurrent result.- 从以下版本开始:
- 4.0
-
getAsyncWebRequest
-
createAsyncWebRequest
-
getAsyncManager
-
setWebAsyncManagerFactory
-
createWebAsyncManager
-
requestCompleted
public void requestCompleted()Signal that the request has been completed.Executes all request destruction callbacks and other resources cleanup
-
requestCompleted
Signal that the request has been completed.Executes all request destruction callbacks and other resources cleanup
- 参数:
notHandled- exception not handled
-
postRequestCompleted
-
registerRequestDestructionCallback
Register the given callback as to be executed after request completion.- 参数:
callback- the callback to be executed for destruction- 从以下版本开始:
- 4.0
-
registerRequestDestructionCallback
Register the given callback as to be executed after request completion.- 参数:
name- the name of the attribute to register the callback forcallback- the callback to be executed for destruction- 从以下版本开始:
- 4.0
-
removeRequestDestructionCallback
Remove the request destruction callback for the specified attribute, if any.- 参数:
name- the name of the attribute to remove the callback for- 从以下版本开始:
- 4.0
-
isPreFlightRequest
public boolean isPreFlightRequest()Returnstrueif the request is a valid CORS pre-flight one by checking {code OPTIONS} method withOriginandAccess-Control-Request-Methodheaders presence.- 从以下版本开始:
- 4.0
-
isCorsRequest
public boolean isCorsRequest()Returnstrueif the request is a valid CORS one by checkingOriginheader presence and ensuring that origins are different.- 从以下版本开始:
- 4.0
-
getPort
-
getContentType
Returns the MIME type of the body of the request, ornullif the type is not known.- 返回:
- a
Stringcontaining the name of the MIME type of the request, or null if the type is not known
-
requestHeaders
Get request HTTP headers- 返回:
- request read only HTTP header ,never be
null - 从以下版本开始:
- 3.0
-
createRequestHeaders
template method for create request http-headers- 从以下版本开始:
- 3.0
-
getLocale
Returns the preferredLocalethat the client will accept content in, based on the Accept-Language header. If the client request doesn't provide an Accept-Language header, this method returns the default locale for the server.- 返回:
- the preferred
Localefor the client - 从以下版本开始:
- 4.0
-
doGetLocale
-
checkNotModified
public boolean checkNotModified(long lastModifiedTimestamp) Check whether the requested resource has been modified given the supplied last-modified timestamp (as determined by the application).This will also transparently set the "Last-Modified" response header and HTTP status when applicable.
Typical usage:
public String myHandleMethod(RequestContext request, Model model) { long lastModified = // application-specific calculation if (request.checkNotModified(lastModified)) { // shortcut exit - no further processing necessary return null; } // further request processing, actually building content model.addAttribute(...); return "myViewName"; }This method works with conditional GET/HEAD requests, but also with conditional POST/PUT/DELETE requests.
Note: you can use either this
#checkNotModified(long)method; orcheckNotModified(String). If you want enforce both a strong entity tag and a Last-Modified value, as recommended by the HTTP specification, then you should usecheckNotModified(String, long).If the "If-Modified-Since" header is set but cannot be parsed to a date value, this method will ignore the header and proceed with setting the last-modified timestamp on the response.
- 参数:
lastModifiedTimestamp- the last-modified timestamp in milliseconds that the application determined for the underlying resource- 返回:
- whether the request qualifies as not modified, allowing to abort request processing and relying on the response telling the client that the content has not been modified
- 从以下版本开始:
- 4.0
-
checkNotModified
Check whether the requested resource has been modified given the suppliedETag(entity tag), as determined by the application.This will also transparently set the "ETag" response header and HTTP status when applicable.
Typical usage:
public String myHandleMethod(RequestContext request, Model model) { String eTag = // application-specific calculation if (request.checkNotModified(eTag)) { // shortcut exit - no further processing necessary return null; } // further request processing, actually building content model.addAttribute(...); return "myViewName"; }Note: you can use either this
#checkNotModified(String)method; orcheckNotModified(long). If you want enforce both a strong entity tag and a Last-Modified value, as recommended by the HTTP specification, then you should usecheckNotModified(String, long).- 参数:
etag- the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.- 返回:
- true if the request does not require further processing.
- 从以下版本开始:
- 4.0
-
checkNotModified
Check whether the requested resource has been modified given the suppliedETag(entity tag) and last-modified timestamp, as determined by the application.This will also transparently set the "ETag" and "Last-Modified" response headers, and HTTP status when applicable.
Typical usage:
public String myHandleMethod(RequestContext request, Model model) { String eTag = // application-specific calculation long lastModified = // application-specific calculation if (request.checkNotModified(eTag, lastModified)) { // shortcut exit - no further processing necessary return null; } // further request processing, actually building content model.addAttribute(...); return "myViewName"; }This method works with conditional GET/HEAD requests, but also with conditional POST/PUT/DELETE requests.
Note: The HTTP specification recommends setting both ETag and Last-Modified values, but you can also use
#checkNotModified(String)orcheckNotModified(long).- 参数:
eTag- the entity tag that the application determined for the underlying resource. This parameter will be padded with quotes (") if necessary.lastModifiedTimestamp- the last-modified timestamp in milliseconds that the application determined for the underlying resource- 返回:
- true if the request does not require further processing.
- 从以下版本开始:
- 4.0
-
validateIfMatch
-
validateIfNoneMatch
-
matchRequestedETags
-
padEtagIfNecessary
-
eTagStrongMatch
-
eTagWeakMatch
-
updateResponseStateChanging
-
validateIfUnmodifiedSince
private boolean validateIfUnmodifiedSince(long lastModifiedTimestamp) -
validateIfModifiedSince
private void validateIfModifiedSince(long lastModifiedTimestamp) -
updateResponseIdempotent
-
addCachingResponseHeaders
-
isNotModified
public boolean isNotModified() -
parseDateHeader
-
parseDateValue
-
setBinding
- 从以下版本开始:
- 4.0
-
hasBinding
public boolean hasBinding()- 从以下版本开始:
- 4.0
-
getBinding
- 从以下版本开始:
- 4.0
-
binding
- 抛出:
IllegalStateException- if BindingContext is not set- 从以下版本开始:
- 4.0
-
getInputRedirectModel
Return read-only "input" flash attributes from request before redirect.- 返回:
- a RedirectModel, or
nullif not found - 另请参阅:
-
getInputRedirectModel
Return read-only "input" flash attributes from request before redirect.- 参数:
manager- RedirectModelManager manage RedirectModel- 返回:
- a RedirectModel, or
nullif not found - 另请参阅:
-
setContentLength
public void setContentLength(long length) Sets the length of the content body in the response , this method sets the HTTP Content-Length header.- 参数:
length- an long specifying the length of the content being returned to the client; sets the Content-Length header
-
isCommitted
public abstract boolean isCommitted()Returns a boolean indicating if the response has been committed. A committed response has already had its status code and headers written.- 返回:
- a boolean indicating if the response has been committed
- 另请参阅:
-
reset
public void reset()Clears any data that exists in the buffer as well as the status code, headers. The state of callinggetWriter()orgetOutputStream()is also cleared. It is legal, for instance, to callgetWriter(), reset() and thengetOutputStream(). IfgetWriter()orgetOutputStream()have been called before this method, then the corresponding returned Writer or OutputStream will be staled and the behavior of using the stale object is undefined. If the response has been committed, this method throws anIllegalStateException.- 抛出:
IllegalStateException- if the response has already been committed
-
sendRedirect
Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer. The buffer will be replaced with the data set by this method. Calling this method sets the status code to 302 (Found). This method can accept relative URLs;the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root. If the location is relative with two leading '/' the container interprets it as a network-path reference (see RFC 3986: Uniform Resource Identifier (URI): Generic Syntax, section 4.2 "Relative Reference").If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
- 参数:
location- the redirect location URL- 抛出:
IOException- If an input or output exception occursIllegalStateException- If the response was committed or if a partial URL is given and cannot be converted into a valid URL
-
setStatus
public abstract void setStatus(int sc) Sets the status code for this response.This method is used to set the return status code when there is no error .
This method preserves any cookies and other response headers.
Valid status codes are those in the 2XX, 3XX, 4XX, and 5XX ranges. Other status codes are treated as container specific.
- 参数:
sc- the status code
-
setStatus
Sets the status code and message for this response.- 参数:
status- the status
-
getStatus
public abstract int getStatus()Gets the current status code of this response.- 返回:
- the current status code of this response
-
sendError
Sends an error response to the client using the specified status code and clears the buffer. The server will preserve cookies and may clear or update any headers needed to serve the error page as a valid response. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back the error pageIf the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
- 参数:
code- the error status code- 抛出:
IOException- If an input or output exception occursIllegalStateException- If the response was committed before this method call- 从以下版本开始:
- 4.0
-
sendError
Sends an error response to the client using the specified status and clears the buffer. The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html". The caller is not responsible for escaping or re-encoding the message to ensure it is safe with respect to the current response encoding and content type. This aspect of safety is the responsibility of the container, as it is generating the error page containing the message. The server will preserve cookies and may clear or update any headers needed to serve the error page as a valid response.
If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter and the msg parameter will be ignored.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
- 参数:
code- the error status codemsg- the descriptive message- 抛出:
IOException- If an input or output exception occursIllegalStateException- If the response was committed- 从以下版本开始:
- 4.0
-
sendError
Sends an error response to the client using the specified status code and clears the buffer. The server will preserve cookies and may clear or update any headers needed to serve the error page as a valid response. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back the error pageIf the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
- 参数:
sc- the error status code- 抛出:
IOException- If an input or output exception occursIllegalStateException- If the response was committed before this method call
-
sendError
Sends an error response to the client using the specified status and clears the buffer. The server defaults to creating the response to look like an HTML-formatted server error page containing the specified message, setting the content type to "text/html". The caller is not responsible for escaping or re-encoding the message to ensure it is safe with respect to the current response encoding and content type. This aspect of safety is the responsibility of the container, as it is generating the error page containing the message. The server will preserve cookies and may clear or update any headers needed to serve the error page as a valid response.
If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back in preference to the suggested msg parameter and the msg parameter will be ignored.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
- 参数:
sc- the error status codemsg- the descriptive message- 抛出:
IOException- If an input or output exception occursIllegalStateException- If the response was committed
-
getOutputStream
Returns aOutputStreamsuitable for writing binary data in the response. The Server container does not encode the binary data.Calling flush() on the
OutputStreamcommits the response. Either this method orgetWriter()may be called to write the body, not both, except whenreset()has been called.- 指定者:
getOutputStream在接口中cn.taketoday.core.io.OutputStreamSource- 返回:
- a
OutputStreamfor writing binary data - 抛出:
IllegalStateException- For Servlet Environment if thegetWritermethod has been called on this responseIOException- if an input or output exception occurred- 另请参阅:
-
doGetOutputStream
template method for get OutputStream- 抛出:
IOException
-
getWriter
Returns aPrintWriterobject that can send character text to the client. ThePrintWriteruses the UTF-8 character encoding.Calling flush() on the
PrintWritercommits the response.Either this method or
getOutputStream()may be called to write the body, not both, except whenreset()has been called.- 指定者:
getWriter在接口中cn.taketoday.core.io.OutputStreamSource- 返回:
- a
PrintWriterobject that can return character data to the client - 抛出:
IOException- if an input or output exception occurredIllegalStateException- For Servlet Environment if thegetOutputStreammethod has already been called for this response object- 另请参阅:
-
doGetWriter
template method for get writer- 抛出:
IOException
-
setContentType
Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example,text/html;charset=UTF-8. The response's character encoding is only set from the given content type if this method is called beforegetWriteris called.This method may be called repeatedly to change content type and character encoding. This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after
getWriterhas been called or after the response has been committed.Containers must communicate the content type and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the
Content-Typeheader is used.- 参数:
contentType- aStringspecifying the MIME type of the content
-
setContentType
Sets the content type of the response being sent to the client, if the response has not been committed yet. The given content type may include a character encoding specification, for example,text/html;charset=UTF-8. The response's character encoding is only set from the given content type if this method is called beforegetWriteris called.This method may be called repeatedly to change content type and character encoding. This method has no effect if called after the response has been committed. It does not set the response's character encoding if it is called after
getWriterhas been called or after the response has been committed.Containers must communicate the content type and the character encoding used for the servlet response's writer to the client if the protocol provides a way for doing so. In the case of HTTP, the
Content-Typeheader is used.- 参数:
contentType- aStringspecifying the MIME type of the content
-
getResponseContentType
Returns the content type used for the MIME body sent in this response. The content type proper must have been specified usingsetContentType(java.lang.String)before the response is committed. If no content type has been specified, this method returns null.- 返回:
- a
Stringspecifying the content type, for example,text/html; charset=UTF-8, or null - 另请参阅:
-
responseHeaders
Get request HTTP headers- 从以下版本开始:
- 3.0
-
mergeToResponse
merge headers to response http-headers- 从以下版本开始:
- 3.0
-
createResponseHeaders
create a new response http-header- 从以下版本开始:
- 3.0
-
asHttpOutputMessage
-
nativeRequest
public abstract <T> T nativeRequest()Native request eg: HttpServletRequest -
unwrapRequest
- 参数:
requestClass- wrapped request class- 返回:
- returns
nullindicated that not a requestClass
-
flush
Forces any content in the buffer to be written to the client. A call to this method automatically commits the response, meaning the status code and headers will be written. Ensure that the headers and the content of the response are written out.After the first flush, headers can no longer be changed. Only further content writing and content flushing is possible.
- 抛出:
IOException- if the act of flushing the buffer cannot be completed.- 另请参阅:
-
writeHeaders
public void writeHeaders()write headers to response- 从以下版本开始:
- 4.0
-
toString
-