Class: Rack::Inflater

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/inflater.rb,
lib/rack/inflater/railtie.rb,
lib/rack/inflater/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
"0.1.0".freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Inflater

Returns a new instance of Inflater.



7
8
9
# File 'lib/rack/inflater.rb', line 7

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rack/inflater.rb', line 11

def call(env)
  if decompress?(env)
    character_set = env["rack.input".freeze].external_encoding
    extracted = decode(
      env["rack.input".freeze],
      env["HTTP_CONTENT_ENCODING".freeze]
    )

    env.delete("HTTP_CONTENT_ENCODING".freeze)
    env["CONTENT_LENGTH".freeze] = extracted.bytesize
    input = StringIO.new(extracted).set_encoding(character_set).set_encoding("UTF-8")
    env['rack.input'.freeze] = input
  end

  @app.call(env)
end