i have a programmatic Undertow server setup. Static content is served by Undertow as well, without a reverse proxy. Java code for Undertow startup looks like this:
ResourceManager resourceManager =
new FileResourceManager(new File("deploymentDir"), 100);
DeploymentInfo servletBuilder = Servlets.deployment()
.setResourceManager(resourceManager)
.setDeploymentName("testDeployment")
.setContextPath("/");
DeploymentManager manager = Servlets.defaultContainer()
.addDeployment(servletBuilder);
manager.deploy();
Undertow.Builder builder = Undertow.builder();
builder.addHttpListener(8080, domainName);
PathHandler path = Handlers.path(Handlers.redirect("/"))
.addPrefixPath("/", manager.start());
Undertow server = builder.setHandler(path).build();
server.start();
I'm wondering how does one gzip server responses in Undertow?
Thanks, Vitaliy.
server.compression.enabled= true. # Minimum response where compression will kick in. server.compression.min-response-size= 4096. # Mime types that should be compressed. server.compression.mime-types=text/html, text/xml, text/plain, text/css, text/javascript, application/javascript, application/json.
Gzip on Windows Servers (IIS Manager)Open up IIS Manager. Click on the site you want to enable compression for. Click on Compression (under IIS) Now Enable static compression and you are done!
Undertow is a web server which is able to perform both blocking and non-blocking tasks. Some of its highlights are: You can used it embedded or inside WildFly application server. Features High Performance. Supports Servlet 4.0 and Web Sockets API.
I had to look at GzipContentEncodingTestCase
in Undertow's source to get it to work. One has to create an EncodingHandler
with appropriate parameters, and then invoke setNext()
so that to chain it to the PathHandler
:
PathHandler path = Handlers.path(Handlers.redirect("/"))
.addPrefixPath("/", manager.start());
final EncodingHandler handler =
new EncodingHandler(new ContentEncodingRepository()
.addEncodingHandler("gzip",
new GzipEncodingProvider(), 50,
Predicates.parse("max-content-size[5]")))
.setNext(path);
// ...
Undertow server = builder.setHandler(handler).build();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With