module H2::Server::ContentEncoder

Public Instance Methods

check_accept_encoding() click to toggle source

checks the request for accept-encoding headers and processes body accordingly

# File lib/h2/server/stream.rb, line 190
def check_accept_encoding
  if accept = @stream.request.headers[ACCEPT_ENCODING_KEY]
    accept.split(',').map(&:strip).each do |encoding|
      case encoding
      when GZIP_ENCODING
        if @stream.connection.server.options[:gzip]
          @body = ::Zlib.gzip @body
          @headers[CONTENT_ENCODING_KEY] = GZIP_ENCODING
          break
        end

      # "deflate" has issues: https://zlib.net/zlib_faq.html#faq39
      #
      when DEFLATE_ENCODING
        if @stream.connection.server.options[:deflate]
          @body = ::Zlib.deflate @body
          @headers[CONTENT_ENCODING_KEY] = DEFLATE_ENCODING
          break
        end

      end
    end
  end
end