-
Notifications
You must be signed in to change notification settings - Fork 0
Compression
Please take a look at https://github.com/linkedin/rest.li/blob/master/r2/src/main/java/com/linkedin/r2/filter/compression/EncodingType.java to see which algorithms are currently supported.
There is no hand-shake protocol between the server and the client to make sure that the server supports a particular compression algorithm. If the client sends a request compressed using an algorithm that the server is not configured with then the client request will fail as the server will not be able to decompress it
Please take a look at: https://github.com/linkedin/rest.li/blob/master/examples/guice-server/server/src/main/java/com/example/fortune/inject/FortunesGuiceServletConfig.java to see how the server has to be configured.
In particular
FilterChain filterChain = FilterChains.create(
new ServerCompressionFilter(new EncodingType[] { EncodingType.SNAPPY }),
new SimpleLoggingFilter());This instantiates a Rest.li server that supports SNAPPY compression. To support SNAPPY and GZIP for example, you would have to instantiate your server as follows:
FilterChain filterChain = FilterChains.create(
new ServerCompressionFilter(new EncodingType[] { EncodingType.SNAPPY, EncodingType.GZIP }),
new SimpleLoggingFilter());When we say that a server supports a particular algorithm for compression, it means that the server can compress and decompress using that algorithm. When to compress and decompress is governed by the client request.
Please take a look at: https://github.com/linkedin/rest.li/blob/master/examples/guice-server/client/src/main/java/com/example/fortune/RestLiFortunesClient.java to see how the client has to be configured.
In particular
final HttpClientFactory http = new HttpClientFactory(FilterChains.create(
new ClientCompressionFilter(EncodingType.IDENTITY, new EncodingType[]{ EncodingType.SNAPPY}, "*")
));This snippet instructs Rest.li to use IDENTITY (a.k.a no compression) for requests to the server. In other words, the HTTP "Content-Encoding" header will be set to "identity". Thus, the first argument dictates the value of the "Content-Encoding" header.
The second argument dictates the value of the "Accept-Encoding" header. In the snippet above, each request to the server will have "Accept-Encoding" set to "snappy". Why every request? Because the third argument is set to "". "" means that each and every request to the server will have an "Accept-Encoding" header present. The third argument is a String of comma separated values, where the values can be "*", a method name, or a family.
- "*": add the "Accept-Encoding" header to all outgoing requests.
- a method name: add the "Accept-Encoding" header only for requests for the particular method. E.g. "get" would add it for get requests, "get, batch_get" would add it for get and batch_get requests etc.
- a family: add the "Accept-Encoding" header only for requests for a method that matches the family. A family is specified as method:. E.g. "action:" would add it for all actions, "finder:*" would add it for all finder requests etc.
The above three can be mixed. For example, to have compression on get, batch_get and all finders, the third argument would be "get, batch_get, finder:*"