Skip to content

Websocket extensions not working #26449

Closed
@piotrblasiak

Description

@piotrblasiak

Affects: \5.3.3


In spring, one can add an undertow websocket extension by:
 

@Bean
    public WebServerFactoryCustomizer<UndertowServletWebServerFactory> deploymentCustomizer() {
        return factory -> {
            UndertowDeploymentInfoCustomizer customizer = deploymentInfo -> {

                WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo();
                webSocketDeploymentInfo.addExtension(new PerMessageDeflateHandshake());
                deploymentInfo.addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME, webSocketDeploymentInfo);
            };
            factory.addDeploymentInfoCustomizers(customizer); 
        };
    }

But that extension does not work when processing requests. I have found that spring wraps extensions in
org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.getInstalledExtensions(...)

protected List<WebSocketExtension> getInstalledExtensions(WebSocketContainer container) {
		List<WebSocketExtension> result = new ArrayList<>();
		for (Extension extension : container.getInstalledExtensions()) {
			result.add(new StandardToWebSocketExtensionAdapter(extension));
		}
		return result;
	}

which breaks the extension matching in 

org.springframework.web.socket.server.support.filterRequestedExtensions(...)

protected List<WebSocketExtension> filterRequestedExtensions(ServerHttpRequest request,
			List<WebSocketExtension> requestedExtensions, List<WebSocketExtension> supportedExtensions) {

		List<WebSocketExtension> result = new ArrayList<>(requestedExtensions.size());
		for (WebSocketExtension extension : requestedExtensions) {
			if (supportedExtensions.contains(extension)) {
				result.add(extension);
			}
		}
		return result;
	}

I have been unable to find a workaround for this, and I am not sure what an appropriate fix would be.

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions