Method: CompressedRequests#call

Defined in:
lib/logstash/util/http_compressed_requests.rb

#call(env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logstash/util/http_compressed_requests.rb', line 14

def call(env)
  if method_handled?(env) && encoding_handled?(env)
    begin
      extracted = decode(env['rack.input'], env['HTTP_CONTENT_ENCODING'])
    rescue Zlib::Error
      return [400, {'Content-Type' => 'text/plain'}, ["Failed to decompress body"]]
    end

    env.delete('HTTP_CONTENT_ENCODING')
    env['CONTENT_LENGTH'] = extracted.bytesize
    env['rack.input'] = StringIO.new(extracted)
  end

  @app.call(env)
end