Module: H2::Server::ContentEncoder

Included in:
Stream::PushPromise, Stream::Response
Defined in:
lib/h2/server/stream.rb

Instance Method Summary collapse

Instance Method Details

#check_accept_encodingObject

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



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# 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