14

I'm with a problem to configure the GZip in my Wildfly server used the following configuration on the server:

<subsystem xmlns="urn:jboss:domain:undertow:1.2">
        <buffer-cache name="default"/>
        <server name="default-server">
            <http-listener name="default" socket-binding="http"/>
            <host name="default-host" alias="localhost">
                <location name="/" handler="welcome-content"/>
                <filter-ref name="gzipFilter" predicate="path-suffix['.css'] or path-suffix['.js'] or path-suffix['.xhtml']"/>
                <filter-ref name="server-header"/>
                <filter-ref name="x-powered-by-header"/>
            </host>
        </server>
        <servlet-container name="default">
            <jsp-config/>
            <websockets/>
        </servlet-container>
        <handlers>
            <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
        </handlers>
        <filters>
            <response-header name="server-header" header-name="Server" header-value="Wildfly 8"/>
            <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow 1"/>
            <gzip name="gzipFilter"/>
        </filters>
    </subsystem>

And became the Zip file of the request correctly, however I would like to set the minimum size for files to be zipped and what I'm hard, anyone know how to set the minimum size for the server do the zip before sends them to the customer?

user2296155
  • 243
  • 1
  • 2
  • 8

3 Answers3

17

Expanding on Alexander's answer I did some tests. Strangely enough the predicate to only compress files larger then 500 bytes is not min-content-size[500].

To configure it using jboss-cli.sh run this script:

/subsystem=undertow/configuration=filter/gzip=gzipFilter:add()
/subsystem=undertow/server=default-server/host=default-host/\
   filter-ref=gzipFilter:add(predicate="not min-content-size[500]")

Note that the gzip filter will start to work after server reload. You can do this using cli's command :reload.

To test if the filter is enabled I used:

wget $MY_URL -S --header="accept-encoding: gzip" \
  -O /dev/null 2>&1| grep Content-Encoding
rzymek
  • 9,064
  • 2
  • 45
  • 59
  • 5
    **Update**: Wildfly 10 shows the under warning when you use `predicate[value]`. You should change to `predicate(value)`. But, Wildfly 9 doesn't accept `predicate(value)`, it raises a ParseException. `Predicate not min-content-size[2048] uses old style square braces to define predicates, which will be removed in a future release. predicate[value] should be changed to predicate(value)` – Marcelo Barros Sep 04 '17 at 17:48
  • 1
    `min-content-size[500]` works with "Content-Length" header. If it not exists, this predicate returns false. So the meaning of `not min-content-size[500]` is: apply gzip IF the response has Content-Length > 500 OR the response has not Content-Length header. To change the last part of the predicate you can change it to `exists['%{o,Content-Length}'] and not min-content-size[500]` or to `max-content-size[500]`. – McGiogen Sep 13 '17 at 08:42
8

There is a predicate in undertow min-content-size so you can use predicate=min-content-size[500]

I found the available predicates here https://github.com/undertow-io/undertow/tree/master/core/src/main/java/io/undertow/predicate due to lack of documentation

Alexander
  • 3,019
  • 1
  • 20
  • 24
1

It worked with the predicate:

predicate="exists['%{o,Content-Type}'] and regex[pattern='(?:application/javascript|text/css|text/html|text/xml|application/json)(;.*)?', value=%{o,Content-Type}, full-match=true]"