Interface ServletWebSocketUpgrader

All Known Implementing Classes:
JakartaWebSocketUpgrader

public interface ServletWebSocketUpgrader
Strategy for switching a matched WebSocket upgrade request over to a WebSocket implementation once the Micronaut filter chain has approved the handshake.

An implementation of this interface is contributed by the micronaut-servlet-websocket module. When no implementation is present the server has no WebSocket support and upgrade requests are handled as ordinary HTTP requests.

Since:
6.2.0
Author:
graemerocher
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The websocket token used by the Upgrade header.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isWebSocketUpgrade(@NonNull io.micronaut.http.HttpRequest<?> request)
    Whether the given request is a WebSocket upgrade request.
    void
    upgrade(@NonNull ServletExchange<?,?> exchange, @NonNull io.micronaut.http.HttpRequest<?> request, @NonNull io.micronaut.web.router.UriRouteMatch<?,?> routeMatch, @NonNull io.micronaut.http.HttpResponse<?> handshakeResponse)
    Switch the given exchange over to the WebSocket protocol.
  • Field Details

  • Method Details

    • upgrade

      void upgrade(@NonNull ServletExchange<?,?> exchange, @NonNull io.micronaut.http.HttpRequest<?> request, @NonNull io.micronaut.web.router.UriRouteMatch<?,?> routeMatch, @NonNull io.micronaut.http.HttpResponse<?> handshakeResponse) throws Exception
      Switch the given exchange over to the WebSocket protocol.

      Implementations are invoked on the container thread that is dispatching the request and before any asynchronous processing has been started, since servlet containers require the upgrade to happen while the original request is still being dispatched.

      Parameters:
      exchange - The exchange being upgraded
      request - The originating HTTP request
      routeMatch - The matched WebSocket route
      handshakeResponse - The response produced by the Micronaut filter chain, any headers of which should be carried over to the handshake response
      Throws:
      Exception - if the upgrade cannot be performed
    • isWebSocketUpgrade

      static boolean isWebSocketUpgrade(@NonNull io.micronaut.http.HttpRequest<?> request)
      Whether the given request is a WebSocket upgrade request.

      A request qualifies when it is a GET request that carries Upgrade: websocket and a Connection header listing the upgrade token, as required by RFC 6455.

      Parameters:
      request - The request
      Returns:
      true if the request is a WebSocket upgrade request