程序包 cn.taketoday.web

类 RequestContext

java.lang.Object
cn.taketoday.core.AttributeAccessorSupport
cn.taketoday.web.RequestContext
所有已实现的接口:
cn.taketoday.core.AttributeAccessor, cn.taketoday.core.io.InputStreamSource, cn.taketoday.core.io.OutputStreamSource, HttpInputMessage, HttpMessage, HttpRequest, Serializable
直接已知子类:
DecoratingRequestContext, DefaultServerRequest.CheckNotModifiedResponse, ServletRequestContext

public abstract class RequestContext extends cn.taketoday.core.AttributeAccessorSupport implements cn.taketoday.core.io.InputStreamSource, cn.taketoday.core.io.OutputStreamSource, HttpInputMessage, HttpRequest, cn.taketoday.core.AttributeAccessor
Context holder for request-specific state.
从以下版本开始:
2.3.7
作者:
TODAY 2019-06-22 15:48
另请参阅:
  • 字段详细资料

    • serialVersionUID

      private static final long serialVersionUID
      另请参阅:
    • SCOPE_REQUEST

      public static final String SCOPE_REQUEST
      Scope identifier for request scope: "request". Supported in addition to the standard scopes "singleton" and "prototype".
      另请参阅:
    • SCOPE_SESSION

      public static final String SCOPE_SESSION
      Scope identifier for session scope: "session". Supported in addition to the standard scopes "singleton" and "prototype".
      另请参阅:
    • SAFE_METHODS

      private static final List<String> SAFE_METHODS
    • DATE_FORMATS

      private static final String[] DATE_FORMATS
      Date formats as specified in the HTTP RFC.
      另请参阅:
    • GMT

      private static final TimeZone GMT
    • EMPTY_COOKIES

      public static final HttpCookie[] EMPTY_COOKIES
    • contextPath

      protected String contextPath
    • cookies

      protected HttpCookie[] cookies
    • writer

      protected PrintWriter writer
    • reader

      protected BufferedReader reader
    • inputStream

      protected InputStream inputStream
    • outputStream

      protected OutputStream outputStream
    • requestHeaders

      protected HttpHeaders requestHeaders
      从以下版本开始:
      3.0
    • responseHeaders

      protected HttpHeaders responseHeaders
      从以下版本开始:
      3.0
    • method

      protected String method
      从以下版本开始:
      3.0
    • requestURI

      protected String requestURI
      从以下版本开始:
      3.0
    • requestPath

      protected RequestPath requestPath
      从以下版本开始:
      4.0
    • parameters

      protected Map<String,String[]> parameters
      从以下版本开始:
      3.0
    • queryString

      protected String queryString
      从以下版本开始:
      3.0
    • responseCookies

      protected ArrayList<HttpCookie> responseCookies
      从以下版本开始:
      3.0
    • uri

      protected URI uri
      从以下版本开始:
      4.0
    • httpMethod

      protected HttpMethod httpMethod
      从以下版本开始:
      4.0
    • lookupPath

      protected PathContainer lookupPath
      从以下版本开始:
      4.0
    • pathWithinApplication

      protected PathContainer pathWithinApplication
      从以下版本开始:
      4.0
    • locale

      protected Locale locale
      从以下版本开始:
      4.0
    • responseContentType

      protected String responseContentType
      从以下版本开始:
      4.0
    • applicationContext

      protected final cn.taketoday.context.ApplicationContext applicationContext
      从以下版本开始:
      4.0
    • multipartRequest

      protected MultipartRequest multipartRequest
      从以下版本开始:
      4.0
    • asyncWebRequest

      protected AsyncWebRequest asyncWebRequest
      从以下版本开始:
      4.0
    • webAsyncManager

      protected WebAsyncManager webAsyncManager
    • notModified

      protected boolean notModified
    • matchingMetadata

      @Nullable private HandlerMatchingMetadata matchingMetadata
    • bindingContext

      @Nullable protected BindingContext bindingContext
    • redirectModel

      @Nullable protected Object redirectModel
    • multipartFlag

      protected Boolean multipartFlag
    • preFlightRequestFlag

      protected Boolean preFlightRequestFlag
    • corsRequestFlag

      protected Boolean corsRequestFlag
    • requestDestructionCallbacks

      protected LinkedHashMap<String,Runnable> requestDestructionCallbacks
      Map from attribute name String to destruction callback Runnable. @since 4.0
    • requestCompletedTimeMillis

      private long requestCompletedTimeMillis
    • id

      @Nullable private String id
    • webAsyncManagerFactory

      private WebAsyncManagerFactory 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

      public String 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

      @Nullable protected String initId()
      Obtain the request id to use, or null in which case the Object identity of this request instance is used.
    • getScheme

      public abstract String getScheme()
      Returns the name of the scheme used to make this request, for example, http, https, or ftp. Different schemes have different rules for constructing URLs, as noted in RFC 1738.
      返回:
      a String containing the name of the scheme used to make this request
      从以下版本开始:
      3.0.1
    • getServerName

      public abstract String getServerName()
      Returns the host name of the server to which the request was sent. It is the value of the part before ":" in the Host header value, if any, or the resolved server name, or the server IP address.
      返回:
      a String containing 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 the Host header value, if any, or the server port where the client connection was accepted on.
      返回:
      an integer specifying the port number
      从以下版本开始:
      4.0
    • getContextPath

      public String 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 String specifying the portion of the request URI that indicates the context of the request
    • doGetContextPath

      protected String doGetContextPath()
    • getURI

      public URI getURI()
      从接口复制的说明: HttpRequest
      Return 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

      public String 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 String containing the part of the URL from the protocol name up to the query string
    • getRequestPath

      public RequestPath getRequestPath()
      另请参阅:
    • doGetRequestPath

      protected RequestPath doGetRequestPath()
    • getLookupPath

      public PathContainer getLookupPath()
      从以下版本开始:
      4.0
    • setMatchingMetadata

      public void setMatchingMetadata(@Nullable HandlerMatchingMetadata handlerMatchingMetadata)
    • getMatchingMetadata

      @Nullable public HandlerMatchingMetadata getMatchingMetadata()
    • matchingMetadata

      public HandlerMatchingMetadata matchingMetadata()
      抛出:
      IllegalStateException - if HandlerMatchingMetadata is not set
      从以下版本开始:
      4.0
    • hasMatchingMetadata

      public boolean hasMatchingMetadata()
    • doGetRequestURI

      protected abstract String doGetRequestURI()
    • getRequestURL

      public String 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

      public String getQueryString()
      Returns the query string that is contained in the request URL after the path. This method returns null if the URL does not have a query string. Same as the value of the CGI variable QUERY_STRING.
      返回:
      a String containing the query string or null if the URL contains no query string. The value is not decoded by the container.
    • doGetQueryString

      protected abstract String doGetQueryString()
    • getCookies

      public HttpCookie[] getCookies()
      Returns an array containing all of the Cookie objects the client sent with this request. This method returns null if no cookies were sent.
      返回:
      an array of all the Cookies included with this request, or EMPTY_COOKIES if the request has no cookies
    • doGetCookies

      protected abstract HttpCookie[] doGetCookies()
      返回:
      an array of all the Cookies included with this request,or EMPTY_COOKIES if the request has no cookies
    • getCookie

      @Nullable public HttpCookie getCookie(String name)
      Returns a HttpCookie object the client sent with this request. This method returns null if no target cookie were sent.
      参数:
      name - Cookie name
      返回:
      a HttpCookie object the client sent with this request. This method returns null if no target cookie were sent.
      从以下版本开始:
      2.3.7
    • addCookie

      public void addCookie(HttpCookie cookie)
      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

      public void addCookie(String name, @Nullable String value)
      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 client
      value - the Cookie value to return to the client
    • removeCookie

      public List<HttpCookie> removeCookie(String name)
      remove the specified cookie from response
      参数:
      name - cookie name
      返回:
      removed cookie
    • responseCookies

      public ArrayList<HttpCookie> responseCookies()
    • getParameters

      public Map<String,String[]> 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

      protected Map<String,String[]> doGetParameters()
    • postGetParameters

      protected void postGetParameters(cn.taketoday.util.MultiValueMap<String,String> parameters)
    • getParameterNames

      public Iterator<String> getParameterNames()
      Returns an Iterator of String objects containing the names of the parameters contained in this request. If the request has no parameters, the method returns an empty Iterator.
      返回:
      an Iterator of String objects, each String containing the name of a request parameter; or an empty Iterator if the request has no parameters
    • getParameters

      @Nullable public String[] getParameters(String name)
      Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.

      If the parameter has a single value, the array has a length of 1.

      参数:
      name - a String containing the name of the parameter whose value is requested
      返回:
      an array of String objects containing the parameter's values
      另请参阅:
    • getParameter

      @Nullable public String getParameter(String name)
      Returns the value of a request parameter as a String, or null if 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() or getReader() can interfere with the execution of this method.

      参数:
      name - a String specifying the name of the parameter
      返回:
      a String representing the single value of the parameter
      另请参阅:
    • getMethodValue

      @NonNull public String getMethodValue()
      Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.
      指定者:
      getMethodValue 在接口中 HttpRequest
      返回:
      a String specifying the name of the method with which this request was made
      另请参阅:
    • getMethod

      @NonNull public HttpMethod getMethod()
      从接口复制的说明: HttpRequest
      Return the HTTP method of the request.
      指定者:
      getMethod 在接口中 HttpRequest
      返回:
      the HTTP method as an HttpMethod value
      另请参阅:
    • doGetMethod

      protected abstract String doGetMethod()
    • getRemoteAddress

      public abstract String getRemoteAddress()
      Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
      返回:
      a String containing 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

      public InputStream getBody() throws IOException
      从接口复制的说明: HttpInputMessage
      Return 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

      public HttpHeaders getHeaders()
      从接口复制的说明: HttpMessage
      Return the headers of this message.
      指定者:
      getHeaders 在接口中 HttpMessage
      返回:
      a corresponding HttpHeaders object (never null)
    • getInputStream

      public InputStream getInputStream() throws IOException
      Retrieves the body of the request as binary data using a InputStream. Either this method or getReader() may be called to read the body, not both.
      指定者:
      getInputStream 在接口中 cn.taketoday.core.io.InputStreamSource
      返回:
      a InputStream object containing the body of the request
      抛出:
      IllegalStateException - For Servlet Environment if the getReader() method has already been called for this request
      IOException - if an input or output exception occurred
    • doGetInputStream

      protected abstract InputStream doGetInputStream() throws IOException
      抛出:
      IOException
    • getReader

      public BufferedReader getReader() throws IOException
      Retrieves the body of the request as character data using a BufferedReader. The reader translates the character data according to the character encoding used on the body. Either this method or getInputStream() may be called to read the body, not both.
      指定者:
      getReader 在接口中 cn.taketoday.core.io.InputStreamSource
      返回:
      a BufferedReader containing the body of the request
      抛出:
      IllegalStateException - For Servlet Environment if getInputStream() method has been called on this request
      IOException - if an input or output exception occurred
      另请参阅:
    • doGetReader

      protected BufferedReader doGetReader() throws IOException
      template method for get reader
      抛出:
      IOException
    • isMultipart

      public boolean isMultipart()
      返回:
      return whether this request is multipart
      从以下版本开始:
      4.0
    • getMultipartRequest

      public MultipartRequest getMultipartRequest()
      从以下版本开始:
      4.0
      另请参阅:
    • createMultipartRequest

      protected abstract MultipartRequest 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

      public AsyncWebRequest getAsyncWebRequest()
    • createAsyncWebRequest

      protected abstract AsyncWebRequest createAsyncWebRequest()
    • getAsyncManager

      public WebAsyncManager getAsyncManager()
    • setWebAsyncManagerFactory

      public void setWebAsyncManagerFactory(WebAsyncManagerFactory webAsyncManagerFactory)
    • createWebAsyncManager

      private WebAsyncManager createWebAsyncManager()
    • requestCompleted

      public void requestCompleted()
      Signal that the request has been completed.

      Executes all request destruction callbacks and other resources cleanup

    • requestCompleted

      public void requestCompleted(@Nullable Throwable notHandled)
      Signal that the request has been completed.

      Executes all request destruction callbacks and other resources cleanup

      参数:
      notHandled - exception not handled
    • postRequestCompleted

      protected void postRequestCompleted(@Nullable Throwable notHandled)
    • registerRequestDestructionCallback

      public final void registerRequestDestructionCallback(Runnable callback)
      Register the given callback as to be executed after request completion.
      参数:
      callback - the callback to be executed for destruction
      从以下版本开始:
      4.0
    • registerRequestDestructionCallback

      public final void registerRequestDestructionCallback(String name, Runnable callback)
      Register the given callback as to be executed after request completion.
      参数:
      name - the name of the attribute to register the callback for
      callback - the callback to be executed for destruction
      从以下版本开始:
      4.0
    • removeRequestDestructionCallback

      public final void removeRequestDestructionCallback(String name)
      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()
      Returns true if the request is a valid CORS pre-flight one by checking {code OPTIONS} method with Origin and Access-Control-Request-Method headers presence.
      从以下版本开始:
      4.0
    • isCorsRequest

      public boolean isCorsRequest()
      Returns true if the request is a valid CORS one by checking Originheader presence and ensuring that origins are different.
      从以下版本开始:
      4.0
    • getPort

      protected static int getPort(@Nullable String scheme, int port)
    • getContentType

      public abstract String getContentType()
      Returns the MIME type of the body of the request, or null if the type is not known.
      返回:
      a String containing the name of the MIME type of the request, or null if the type is not known
    • requestHeaders

      public HttpHeaders requestHeaders()
      Get request HTTP headers
      返回:
      request read only HTTP header ,never be null
      从以下版本开始:
      3.0
    • createRequestHeaders

      protected abstract HttpHeaders createRequestHeaders()
      template method for create request http-headers
      从以下版本开始:
      3.0
    • getLocale

      public Locale getLocale()
      Returns the preferred Locale that 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 Locale for the client
      从以下版本开始:
      4.0
    • doGetLocale

      protected Locale 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; 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(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

      public boolean checkNotModified(String etag)
      Check whether the requested resource has been modified given the supplied ETag (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; or checkNotModified(long). 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(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

      public boolean checkNotModified(@Nullable String eTag, long lastModifiedTimestamp)
      Check whether the requested resource has been modified given the supplied ETag (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) or checkNotModified(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

      private boolean validateIfMatch(@Nullable String eTag)
    • validateIfNoneMatch

      private boolean validateIfNoneMatch(@Nullable String eTag)
    • matchRequestedETags

      private boolean matchRequestedETags(List<String> requestedETags, @Nullable String eTag, boolean weakCompare)
    • padEtagIfNecessary

      @Nullable private String padEtagIfNecessary(@Nullable String etag)
    • eTagStrongMatch

      private boolean eTagStrongMatch(@Nullable String first, @Nullable String second)
    • eTagWeakMatch

      private boolean eTagWeakMatch(@Nullable String first, @Nullable String second)
    • updateResponseStateChanging

      private void updateResponseStateChanging(@Nullable String eTag, long lastModifiedTimestamp)
    • validateIfUnmodifiedSince

      private boolean validateIfUnmodifiedSince(long lastModifiedTimestamp)
    • validateIfModifiedSince

      private void validateIfModifiedSince(long lastModifiedTimestamp)
    • updateResponseIdempotent

      private void updateResponseIdempotent(String eTag, long lastModifiedTimestamp)
    • addCachingResponseHeaders

      private void addCachingResponseHeaders(@Nullable String eTag, long lastModifiedTimestamp)
    • isNotModified

      public boolean isNotModified()
    • parseDateHeader

      private long parseDateHeader(String headerName)
    • parseDateValue

      private long parseDateValue(@Nullable String headerValue)
    • setBinding

      public void setBinding(@Nullable BindingContext bindingContext)
      从以下版本开始:
      4.0
    • hasBinding

      public boolean hasBinding()
      从以下版本开始:
      4.0
    • getBinding

      @Nullable public BindingContext getBinding()
      从以下版本开始:
      4.0
    • binding

      public BindingContext binding()
      抛出:
      IllegalStateException - if BindingContext is not set
      从以下版本开始:
      4.0
    • getInputRedirectModel

      @Nullable public RedirectModel getInputRedirectModel()
      Return read-only "input" flash attributes from request before redirect.
      返回:
      a RedirectModel, or null if not found
      另请参阅:
    • getInputRedirectModel

      @Nullable public RedirectModel getInputRedirectModel(@Nullable RedirectModelManager manager)
      Return read-only "input" flash attributes from request before redirect.
      参数:
      manager - RedirectModelManager manage RedirectModel
      返回:
      a RedirectModel, or null if 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 calling getWriter() or getOutputStream() is also cleared. It is legal, for instance, to call getWriter(), reset() and then getOutputStream(). If getWriter() or getOutputStream() 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 an IllegalStateException.
      抛出:
      IllegalStateException - if the response has already been committed
    • sendRedirect

      public abstract void sendRedirect(String location) throws IOException
      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 occurs
      IllegalStateException - 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

      public void setStatus(HttpStatusCode status)
      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

      public void sendError(HttpStatusCode code) throws IOException
      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 page

      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 code
      抛出:
      IOException - If an input or output exception occurs
      IllegalStateException - If the response was committed before this method call
      从以下版本开始:
      4.0
    • sendError

      public void sendError(HttpStatusCode code, @Nullable String msg) throws IOException

      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 code
      msg - the descriptive message
      抛出:
      IOException - If an input or output exception occurs
      IllegalStateException - If the response was committed
      从以下版本开始:
      4.0
    • sendError

      public abstract void sendError(int sc) throws IOException
      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 page

      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 code
      抛出:
      IOException - If an input or output exception occurs
      IllegalStateException - If the response was committed before this method call
    • sendError

      public abstract void sendError(int sc, @Nullable String msg) throws IOException

      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 code
      msg - the descriptive message
      抛出:
      IOException - If an input or output exception occurs
      IllegalStateException - If the response was committed
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Returns a OutputStream suitable for writing binary data in the response. The Server container does not encode the binary data.

      Calling flush() on the OutputStream commits the response. Either this method or getWriter() may be called to write the body, not both, except when reset() has been called.

      指定者:
      getOutputStream 在接口中 cn.taketoday.core.io.OutputStreamSource
      返回:
      a OutputStream for writing binary data
      抛出:
      IllegalStateException - For Servlet Environment if the getWriter method has been called on this response
      IOException - if an input or output exception occurred
      另请参阅:
    • doGetOutputStream

      protected abstract OutputStream doGetOutputStream() throws IOException
      template method for get OutputStream
      抛出:
      IOException
    • getWriter

      public PrintWriter getWriter() throws IOException
      Returns a PrintWriter object that can send character text to the client. The PrintWriter uses the UTF-8 character encoding.

      Calling flush() on the PrintWriter commits the response.

      Either this method or getOutputStream() may be called to write the body, not both, except when reset() has been called.

      指定者:
      getWriter 在接口中 cn.taketoday.core.io.OutputStreamSource
      返回:
      a PrintWriter object that can return character data to the client
      抛出:
      IOException - if an input or output exception occurred
      IllegalStateException - For Servlet Environment if the getOutputStream method has already been called for this response object
      另请参阅:
    • doGetWriter

      protected PrintWriter doGetWriter() throws IOException
      template method for get writer
      抛出:
      IOException
    • setContentType

      public void setContentType(String contentType)
      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 before getWriter is 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 getWriter has 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-Type header is used.

      参数:
      contentType - a String specifying the MIME type of the content
    • setContentType

      public void setContentType(MediaType contentType)
      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 before getWriter is 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 getWriter has 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-Type header is used.

      参数:
      contentType - a String specifying the MIME type of the content
    • getResponseContentType

      @Nullable public String getResponseContentType()
      Returns the content type used for the MIME body sent in this response. The content type proper must have been specified using setContentType(java.lang.String) before the response is committed. If no content type has been specified, this method returns null.
      返回:
      a String specifying the content type, for example, text/html; charset=UTF-8, or null
      另请参阅:
    • responseHeaders

      public HttpHeaders responseHeaders()
      Get request HTTP headers
      从以下版本开始:
      3.0
    • mergeToResponse

      public void mergeToResponse(HttpHeaders headers)
      merge headers to response http-headers
      从以下版本开始:
      3.0
    • createResponseHeaders

      protected HttpHeaders createResponseHeaders()
      create a new response http-header
      从以下版本开始:
      3.0
    • asHttpOutputMessage

      public ServerHttpResponse asHttpOutputMessage()
    • nativeRequest

      public abstract <T> T nativeRequest()
      Native request eg: HttpServletRequest
    • unwrapRequest

      @Nullable public abstract <T> T unwrapRequest(Class<T> requestClass)
      参数:
      requestClass - wrapped request class
      返回:
      returns null indicated that not a requestClass
    • flush

      public void flush() throws IOException
      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

      public String toString()
      覆盖:
      toString 在类中 Object