UpgradeUtil (Apache Tomcat 9.0.120 API Documentation)
Description: declaration: package: org.apache.tomcat.websocket.server, class: UpgradeUtil

# Class UpgradeUtil

java.lang.Object
org.apache.tomcat.websocket.server.UpgradeUtil

public class UpgradeUtil extends Object
Utility methods for handling WebSocket upgrade requests.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `doUpgrade(WsServerContainer sc, HttpServletRequest req, HttpServletResponse resp, ServerEndpointConfig sec, Map<String,String> pathParams)`
  Performs the WebSocket upgrade handshake.
  `static boolean`
  `isWebSocketUpgradeRequest(ServletRequest request, ServletResponse response)`
  Checks to see if this is an HTTP request that includes a valid upgrade request to web socket.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### isWebSocketUpgradeRequest

    public static boolean isWebSocketUpgradeRequest(ServletRequest request, ServletResponse response)
    Checks to see if this is an HTTP request that includes a valid upgrade request to web socket.

    Note: RFC 2616 does not limit HTTP upgrade to GET requests but the Java WebSocket spec 1.0, section 8.2 implies such a limitation and RFC 6455 section 4.1 requires that a WebSocket Upgrade uses GET.

    Parameters:
      `request` - The request to check if it is an HTTP upgrade request for a WebSocket connection
      `response` - The response associated with the request
    Returns:
      `true` if the request includes an HTTP Upgrade request for the WebSocket protocol, otherwise `false`

  - ### doUpgrade

    public static void doUpgrade(WsServerContainer sc, HttpServletRequest req, HttpServletResponse resp, ServerEndpointConfig sec, Map<String,String> pathParams) throws ServletException, IOException
    Performs the WebSocket upgrade handshake.
    Parameters:
      `sc` - the server container
      `req` - the HTTP request
      `resp` - the HTTP response
      `sec` - the endpoint configuration
      `pathParams` - the path parameters
    Throws:
      `ServletException` - if the upgrade fails
      `IOException` - if an I/O error occurs