Closed samek closed 7 years ago
I never done that before but I did a search and found this link. It looks like we need to add another handler to wrap our business hander.
https://stackoverflow.com/questions/28295752/compressing-undertow-server-responses
Here is an example on how to wrap your handle to serve files from file system as a web server.
Let me know how it goes. Thanks.
Works.
eg.
public` HttpHandler getHandler() {
return new EncodingHandler(new ContentEncodingRepository()
.addEncodingHandler("gzip",
new GzipEncodingProvider(), 50,
Predicates.parse("max-content-size[5]")))
.setNext(
Handlers.routing()
.add(Methods.GET, "/v2/fronts/{front_id}", new FrontGetHandler(Config.getInstance().getMapper()))
.add(Methods.GET, "/v2/articles/{article_id}", new ArticleGetHandler(Config.getInstance().getMapper()))
.add(Methods.GET,"/v2/medias/{media_id}", new MediaGetHandler(Config.getInstance().getMapper()))
.add(Methods.GET,"/v2/menus/{site_id}", new MenuGetHandler(Config.getInstance().getMapper()))
.add(Methods.GET,"/v2/sections/{section_id}", new SectionGetHandler(Config.getInstance().getMapper()))
);
}
@samek Thanks for your confirmation. I will put your findings into the FAQ so that other people can follow your path.
@samek I have added a FAQ section in the document site. Please review and let me know if anything needs to be added/updated. Thanks.
So .. number should definitely be bigger than 5. In my example if max-content-size[5] means it looks at Content-Length: of output on when to enable it. Which is too small. (the gziped response is actually bigger than the response it self would be in really low size outputs).
So I guess if we're going to publish an example this should be noted/changed. What I found on web was that you should enable it above 150 even tho that nginx default is 20.
Otherwise it looks good.
@samek That makes perfect sense. I updated the FAQ to reflect your comment. Thanks.
Hi,
how can I enable compression in the server ?