类 WebUtils

java.lang.Object
cn.taketoday.web.util.WebUtils

public abstract class WebUtils extends Object
Miscellaneous utilities for web applications.

Used by various framework classes.

从以下版本开始:
4.0
作者:
Rod Johnson, Juergen Hoeller, Sebastien Deleuze, Sam Brannen, Harry Yang
  • 字段详细资料

    • ERROR_MESSAGE_ATTRIBUTE

      public static final String ERROR_MESSAGE_ATTRIBUTE
    • ERROR_EXCEPTION_ATTRIBUTE

      public static final String ERROR_EXCEPTION_ATTRIBUTE
    • CONTENT_TYPE_CHARSET_PREFIX

      public static final String CONTENT_TYPE_CHARSET_PREFIX
      Prefix of the charset clause in a content type String: ";charset=".
      另请参阅:
    • SESSION_MUTEX_ATTRIBUTE

      public static final String SESSION_MUTEX_ATTRIBUTE
      Key for the mutex session attribute.
  • 构造器详细资料

    • WebUtils

      public WebUtils()
  • 方法详细资料

    • getSessionMutex

      public static Object getSessionMutex(WebSession session)
      Return the best available mutex for the given session: that is, an object to synchronize on for the given session.

      The session mutex is guaranteed to be the same object during the entire lifetime of the session, available under the key defined by the SESSION_MUTEX_ATTRIBUTE constant. It serves as a safe reference to synchronize on for locking on the current session.

      In many cases, the WebSession reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session mutex.

      参数:
      session - the WebSession to find a mutex for
      返回:
      the mutex object (never null)
      另请参阅:
    • parseMatrixVariables

      public static cn.taketoday.util.MultiValueMap<String,String> parseMatrixVariables(String matrixVariables)
      Parse the given string with matrix variables. An example string would look like this "q1=a;q1=b;q2=a,b,c". The resulting map would contain keys "q1" and "q2" with values ["a","b"] and ["a","b","c"] respectively.
      参数:
      matrixVariables - the unparsed matrix variables string
      返回:
      a map with matrix variable names and values (never null)
    • getNativeContext

      @Nullable public static <T> T getNativeContext(RequestContext request, @Nullable Class<T> requiredType)
      Return an appropriate request object of the specified type, if available, unwrapping the given request as far as necessary.
      参数:
      request - the RequestContext to introspect
      requiredType - the desired type of request object
      返回:
      the matching request object, or null if none of that type is available
    • getSanitizedPath

      public static String getSanitizedPath(String path)
      Sanitize the given path. Uses the following rules:
      • replace all "//" by "/"
    • decodePathVariables

      public static Map<String,String> decodePathVariables(Map<String,String> vars)
      Decode the given URI path variables
      参数:
      vars - the URI variables extracted from the URL path
      返回:
      the same Map or a new Map instance
    • decodeMatrixVariables

      public static cn.taketoday.util.MultiValueMap<String,String> decodeMatrixVariables(cn.taketoday.util.MultiValueMap<String,String> vars)
      Decode the given matrix variables
      参数:
      vars - the URI variables extracted from the URL path
      返回:
      the same Map or a new Map instance
    • removeSemicolonContent

      public static String removeSemicolonContent(String lookupPath)
      Remove ";" (semicolon) content from the given request URI
      参数:
      lookupPath - the request URI string to remove ";" content from
      返回:
      the updated URI string
    • isValidOrigin

      public static boolean isValidOrigin(RequestContext request, Collection<String> allowedOrigins)
      Check the given request origin against a list of allowed origins. A list containing "*" means that all origins are allowed. An empty list means only same origin is allowed.

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

      返回:
      true if the request origin is valid, false otherwise
      另请参阅:
    • isSameOrigin

      public static boolean isSameOrigin(RequestContext request)
      Check if the request is a same-origin one, based on Origin, Host, Forwarded, X-Forwarded-Proto, X-Forwarded-Host and X-Forwarded-Port headers.

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

      返回:
      true if the request is a same-origin one, false in case of cross-origin request
    • getPort

      private static int getPort(@Nullable String scheme, int port)
    • cleanupMultipartRequest

      public static void cleanupMultipartRequest(@Nullable cn.taketoday.util.MultiValueMap<String,Multipart> multipartFiles)