Interface WebSocketDirectives
- All Known Subinterfaces:
Directives
- All Known Implementing Classes:
Directives$
public interface WebSocketDirectives
-
Method Summary
Modifier and TypeMethodDescriptionExtract the list of WebSocket subprotocols as offered by the client in theSec-WebSocket-Protocolheader if this is a WebSocket request.Directive<scala.Tuple1<WebSocketUpgrade>>Extract the WebSocketUpgrade attribute if this is a WebSocket request.scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessages(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler) Handles WebSocket requests with the given handler and rejects other requests with anExpectedWebSocketRequestRejection.scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessages(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, scala.Function1<Message, Object> shouldCompress) Handles WebSocket requests with the given handler and selectively compresses outbound messages for whichshouldCompressreturnstruewhenpermessage-deflatewas negotiated.scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessagesForOptionalProtocol(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, scala.Option<String> subprotocol) Handles WebSocket requests with the given handler and rejects other requests with anExpectedWebSocketRequestRejection.scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessagesForOptionalProtocol(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, scala.Option<String> subprotocol, scala.Function1<Message, Object> shouldCompress) Handles WebSocket requests with the given handler and selectively compresses outbound messages for whichshouldCompressreturnstruewhenpermessage-deflatewas negotiated.scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessagesForProtocol(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, String subprotocol) Handles WebSocket requests with the given handler if the given subprotocol is offered in the request and rejects other requests with anExpectedWebSocketRequestRejectionor anUnsupportedWebSocketSubprotocolRejection.scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessagesForProtocol(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, String subprotocol, scala.Function1<Message, Object> shouldCompress) Handles WebSocket requests with the given handler if the given subprotocol is offered and selectively compresses outbound messages for whichshouldCompressreturnstruewhenpermessage-deflatewas negotiated.
-
Method Details
-
extractOfferedWsProtocols
Extract the list of WebSocket subprotocols as offered by the client in theSec-WebSocket-Protocolheader if this is a WebSocket request. Rejects with anExpectedWebSocketRequestRejection, otherwise.- Returns:
- (undocumented)
-
extractWebSocketUpgrade
Directive<scala.Tuple1<WebSocketUpgrade>> extractWebSocketUpgrade()Extract the WebSocketUpgrade attribute if this is a WebSocket request. Rejects with anExpectedWebSocketRequestRejection, otherwise.- Returns:
- (undocumented)
-
handleWebSocketMessages
scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessages(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler) Handles WebSocket requests with the given handler and rejects other requests with anExpectedWebSocketRequestRejection.- Parameters:
handler- (undocumented)- Returns:
- (undocumented)
-
handleWebSocketMessages
scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessages(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, scala.Function1<Message, Object> shouldCompress) Handles WebSocket requests with the given handler and selectively compresses outbound messages for whichshouldCompressreturnstruewhenpermessage-deflatewas negotiated. The filter is evaluated synchronously once per outbound text or binary message, and the result applies to all fragments. It should be fast and non-blocking; if it throws, the WebSocket stream fails. A streamed message's complete payload and final size are not available when the filter is evaluated.- Parameters:
handler- (undocumented)shouldCompress- (undocumented)- Returns:
- (undocumented)
- Since:
- 2.0.0
-
handleWebSocketMessagesForOptionalProtocol
scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessagesForOptionalProtocol(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, scala.Option<String> subprotocol) Handles WebSocket requests with the given handler and rejects other requests with anExpectedWebSocketRequestRejection.If the
subprotocolparameter is None any WebSocket request is accepted. If thesubprotocolparameter isSome(protocol)a WebSocket request is only accepted if the list of subprotocols supported by the client (as announced in the WebSocket request) containsprotocol. If the client did not offer the protocol in question the request is rejected with anUnsupportedWebSocketSubprotocolRejectionrejection.To support several subprotocols you may chain several
handleWebSocketMessagesForOptionalProtocolroutes.- Parameters:
handler- (undocumented)subprotocol- (undocumented)- Returns:
- (undocumented)
-
handleWebSocketMessagesForOptionalProtocol
scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessagesForOptionalProtocol(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, scala.Option<String> subprotocol, scala.Function1<Message, Object> shouldCompress) Handles WebSocket requests with the given handler and selectively compresses outbound messages for whichshouldCompressreturnstruewhenpermessage-deflatewas negotiated. The filter is evaluated synchronously once per outbound text or binary message, and the result applies to all fragments. It should be fast and non-blocking; if it throws, the WebSocket stream fails. A streamed message's complete payload and final size are not available when the filter is evaluated.- Parameters:
handler- (undocumented)subprotocol- (undocumented)shouldCompress- (undocumented)- Returns:
- (undocumented)
- Since:
- 2.0.0
-
handleWebSocketMessagesForProtocol
scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessagesForProtocol(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, String subprotocol) Handles WebSocket requests with the given handler if the given subprotocol is offered in the request and rejects other requests with anExpectedWebSocketRequestRejectionor anUnsupportedWebSocketSubprotocolRejection.- Parameters:
handler- (undocumented)subprotocol- (undocumented)- Returns:
- (undocumented)
-
handleWebSocketMessagesForProtocol
scala.Function1<RequestContext,scala.concurrent.Future<RouteResult>> handleWebSocketMessagesForProtocol(org.apache.pekko.stream.scaladsl.Flow<Message, Message, Object> handler, String subprotocol, scala.Function1<Message, Object> shouldCompress) Handles WebSocket requests with the given handler if the given subprotocol is offered and selectively compresses outbound messages for whichshouldCompressreturnstruewhenpermessage-deflatewas negotiated. The filter is evaluated synchronously once per outbound text or binary message, and the result applies to all fragments. It should be fast and non-blocking; if it throws, the WebSocket stream fails. A streamed message's complete payload and final size are not available when the filter is evaluated.- Parameters:
handler- (undocumented)subprotocol- (undocumented)shouldCompress- (undocumented)- Returns:
- (undocumented)
- Since:
- 2.0.0
-