Class FkEncoding

  • All Implemented Interfaces:
    Fork

    public final class FkEncoding
    extends Object
    implements Fork
    Fork by encoding accepted by "Accept-Encoding" HTTP header.

    Use this fork in order to deliver responses with different encoding, depending on user preferences. For example, you want to deliver GZIP-compressed response when "Accept-Encoding" request header contains "gzip". Here is how:

     new TkFork(
       new FkEncoding("gzip", new RsGzip(response)),
       new FkEncoding("", response)
     )

    Empty string as an encoding means that the fork should match in any case.

    The class is immutable and thread-safe.

    Since:
    0.10
    See Also:
    RsFork
    • Constructor Detail

      • FkEncoding

        public FkEncoding​(String enc,
                          Response response)
        Ctor.
        Parameters:
        enc - Encoding we accept
        response - Response to return
    • Method Detail

      • route

        public Opt<Response> route​(Request req)
                            throws IOException
        Description copied from interface: Fork
        Process this request or ignore it.
        Specified by:
        route in interface Fork
        Parameters:
        req - Request
        Returns:
        Non-empty list of responses if it was processed
        Throws:
        IOException