Skip to content

Instantly share code, notes, and snippets.

@gastaldi
Created August 23, 2016 17:10
Show Gist options
  • Save gastaldi/96bf2332c840a2825dfac72d85b0de72 to your computer and use it in GitHub Desktop.
Save gastaldi/96bf2332c840a2825dfac72d85b0de72 to your computer and use it in GitHub Desktop.
HTTP/2 Customizer to WildFly Swarm
package org.wildfly.swarm.undertow.runtime;
import javax.enterprise.inject.Any;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import org.wildfly.swarm.config.undertow.Server;
import org.wildfly.swarm.config.undertow.server.HTTPListener;
import org.wildfly.swarm.config.undertow.server.HttpsListener;
import org.wildfly.swarm.spi.api.Customizer;
import org.wildfly.swarm.spi.runtime.annotations.ConfigurationValue;
import org.wildfly.swarm.spi.runtime.annotations.Post;
import org.wildfly.swarm.undertow.UndertowFraction;
/**
* A {@link Customizer} implementation to enable HTTP/2
*
* @author <a href="mailto:[email protected]">George Gastaldi</a>
*/
@Post
public class HTTP2Customizer implements Customizer {
@Inject
@ConfigurationValue("swarm.http2.enabled")
Boolean http2Enabled;
@Inject
@Any
private Instance<UndertowFraction> undertowInstance;
@Override
public void customize() {
UndertowFraction undertowFraction = undertowInstance.get();
if (undertowFraction.isEnableHttp2() || http2Enabled == null || http2Enabled.booleanValue()) {
Server server = undertowFraction.subresources().server("default-server");
for (HTTPListener listener : server.subresources().httpListeners()) {
listener.redirectSocket("default-https").enableHttp2(true);
}
for (HttpsListener listener : server.subresources().httpsListeners()) {
listener.enableHttp2(true);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment