use of io.undertow.websockets.extensions.ExtensionFunction in project undertow by undertow-io.
the class Handshake method initExtensions.
/**
* Create the {@code ExtensionFunction} list associated with the negotiated extensions defined in the exchange's response.
*
* @param exchange the exchange used to retrieve negotiated extensions
* @return a list of {@code ExtensionFunction} with the implementation of the extensions
*/
protected final List<ExtensionFunction> initExtensions(final WebSocketHttpExchange exchange) {
String extHeader = exchange.getResponseHeaders().get(Headers.SEC_WEB_SOCKET_EXTENSIONS_STRING) != null ? exchange.getResponseHeaders().get(Headers.SEC_WEB_SOCKET_EXTENSIONS_STRING).get(0) : null;
List<ExtensionFunction> negotiated = new ArrayList<>();
if (extHeader != null) {
List<WebSocketExtension> extensions = WebSocketExtension.parse(extHeader);
if (extensions != null && !extensions.isEmpty()) {
for (WebSocketExtension ext : extensions) {
for (ExtensionHandshake extHandshake : availableExtensions) {
if (extHandshake.getName().equals(ext.getName())) {
negotiated.add(extHandshake.create());
}
}
}
}
}
return negotiated;
}
use of io.undertow.websockets.extensions.ExtensionFunction in project undertow by undertow-io.
the class WebSocket13ClientHandshake method createChannel.
@Override
public WebSocketChannel createChannel(final StreamConnection channel, final String wsUri, final ByteBufferPool bufferPool, OptionMap options) {
if (negotiation != null && negotiation.getSelectedExtensions() != null && !negotiation.getSelectedExtensions().isEmpty()) {
List<WebSocketExtension> selected = negotiation.getSelectedExtensions();
List<ExtensionFunction> negotiated = new ArrayList<>();
if (selected != null && !selected.isEmpty()) {
for (WebSocketExtension ext : selected) {
for (ExtensionHandshake extHandshake : extensions) {
if (ext.getName().equals(extHandshake.getName())) {
negotiated.add(extHandshake.create());
}
}
}
}
return new WebSocket13Channel(channel, bufferPool, wsUri, negotiation.getSelectedSubProtocol(), true, !negotiated.isEmpty(), CompositeExtensionFunction.compose(negotiated), new HashSet<WebSocketChannel>(), options);
} else {
return new WebSocket13Channel(channel, bufferPool, wsUri, negotiation != null ? negotiation.getSelectedSubProtocol() : "", true, false, NoopExtensionFunction.INSTANCE, new HashSet<WebSocketChannel>(), options);
}
}
Aggregations