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 -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisWebSocketUpgrade(@NonNull io.micronaut.http.HttpRequest<?> request) Whether the given request is a WebSocket upgrade request.voidupgrade(@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
-
WEBSOCKET
-
-
Method Details
-
upgrade
void upgrade(@NonNull ServletExchange<?, ?> exchange, @NonNull io.micronaut.http.HttpRequest<?> request, @NonNull io.micronaut.web.router.UriRouteMatch<?, throws Exception?> routeMatch, @NonNull io.micronaut.http.HttpResponse<?> handshakeResponse) 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 upgradedrequest- The originating HTTP requestrouteMatch- The matched WebSocket routehandshakeResponse- 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
GETrequest that carriesUpgrade: websocketand aConnectionheader listing theupgradetoken, as required by RFC 6455.- Parameters:
request- The request- Returns:
trueif the request is a WebSocket upgrade request
-