protected override Result BeginEncode(IHttpResponse httpResponse, ICharSequence acceptEncoding)
        {
            if (this.contentSizeThreshold > 0)
            {
                if (httpResponse is IHttpContent httpContent &&
                    httpContent.Content.ReadableBytes < this.contentSizeThreshold)
                {
                    return(null);
                }
            }

            if (httpResponse.Headers.Contains(HttpHeaderNames.ContentEncoding))
            {
                // Content-Encoding was set, either as something specific or as the IDENTITY encoding
                // Therefore, we should NOT encode here
                return(null);
            }

            ZlibWrapper?wrapper = this.DetermineWrapper(acceptEncoding);

            if (wrapper is null)
            {
                return(null);
            }

            ICharSequence targetContentEncoding = null;

            switch (wrapper.Value)
            {
            case ZlibWrapper.Gzip:
                targetContentEncoding = GZipString;
                break;

            case ZlibWrapper.Zlib:
                targetContentEncoding = DeflateString;
                break;

            default:
                ThrowHelper.ThrowCodecException_InvalidCompression(wrapper.Value); break;
            }

            return(new Result(targetContentEncoding,
                              new EmbeddedChannel(
                                  this.handlerContext.Channel.Id,
                                  this.handlerContext.Channel.Metadata.HasDisconnect,
                                  this.handlerContext.Channel.Configuration,
                                  ZlibCodecFactory.NewZlibEncoder(
                                      wrapper.Value, this.compressionLevel, this.windowBits, this.memLevel))));
        }