The compression concern compresses content sent to the clients, if applicable. By default, gzip and Brotli are supported.

var content = Layout.Create()

This concern is part of the default configuration and will automatically be added.

Custom Algorithms

To add a custom compression algorithm to the server, you can implement the ICompressionAlgorithm interface and register the implementing class with your server builder. For example, the following implementation will add support for the deflate algorithm, which is not provided by the server out of the box:

public class DeflateCompression : ICompressionAlgorithm
        public string Name => "deflate";
        public Priority Priority => Priority.Low;
        public IResponseContent Compress(IResponseContent content, CompressionLevel level)
            return new CompressedResponseContent(content, (target) => new DeflateStream(target, level, false));
    // registration
    var server = Server.Create()
                       .Defaults(compression: false)
                       .Compression(CompressedContent.Default().Add(new DeflateCompression()));