Class WebSocketUpgradeRequestLifecycle

java.lang.Object
io.micronaut.http.server.RequestLifecycle
io.micronaut.servlet.http.websocket.WebSocketUpgradeRequestLifecycle

@Internal public final class WebSocketUpgradeRequestLifecycle extends io.micronaut.http.server.RequestLifecycle
Runs the Micronaut server filter chain against a WebSocket upgrade request so that filters and security see the handshake before the connection is switched over to the WebSocket protocol.

This mirrors the behaviour of the Netty server: the filter chain is invoked with a sentinel response, and the upgrade only proceeds when that exact response instance survives the chain. A filter that produces its own response (a 401 from micronaut-security, for example) therefore cancels the upgrade and its response is written as an ordinary HTTP response.

Since:
6.2.0
Author:
graemerocher
  • Constructor Summary

    Constructors
    Constructor
    Description
    WebSocketUpgradeRequestLifecycle(io.micronaut.http.server.RouteExecutor routeExecutor, io.micronaut.web.router.Router router)
    Default constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable io.micronaut.web.router.UriRouteMatch<Object,Object>
     
    io.micronaut.core.execution.ExecutionFlow<io.micronaut.http.HttpResponse<?>>
    handle(io.micronaut.http.HttpRequest<?> request)
    Match the request to a WebSocket route and run the filter chain against it.
    boolean
     

    Methods inherited from class io.micronaut.http.server.RequestLifecycle

    findFile, findFile, fulfillArguments, normalFlow, normalFlow, onError, onStatusError, request, runWithFilters

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebSocketUpgradeRequestLifecycle

      public WebSocketUpgradeRequestLifecycle(io.micronaut.http.server.RouteExecutor routeExecutor, io.micronaut.web.router.Router router)
      Default constructor.
      Parameters:
      routeExecutor - The route executor
      router - The router used to look up the WebSocket route
  • Method Details

    • handle

      public io.micronaut.core.execution.ExecutionFlow<io.micronaut.http.HttpResponse<?>> handle(io.micronaut.http.HttpRequest<?> request)
      Match the request to a WebSocket route and run the filter chain against it.
      Parameters:
      request - The upgrade request
      Returns:
      A flow producing either the sentinel response, meaning the upgrade may proceed, or the response a filter substituted for it
    • shouldProceedNormally

      public boolean shouldProceedNormally()
      Returns:
      Whether the upgrade should proceed, meaning no filter substituted a response
    • getRouteMatch

      public @Nullable io.micronaut.web.router.UriRouteMatch<Object,Object> getRouteMatch()
      Returns:
      The matched WebSocket route, or null if no route matched