Class: Rack::Stripper

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/stripper.rb

Constant Summary collapse

VERSION =
'1.1.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Stripper

Returns a new instance of Stripper.



10
11
12
13
# File 'lib/rack/stripper.rb', line 10

def initialize(app, options={})
  @app = app
  @add_xml_instruction = options[:add_xml_instruction] || false
end

Instance Attribute Details

#add_xml_instructionObject

Returns the value of attribute add_xml_instruction.



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

def add_xml_instruction
  @add_xml_instruction
end

#is_xml_responseObject

Returns the value of attribute is_xml_response.



8
9
10
# File 'lib/rack/stripper.rb', line 8

def is_xml_response
  @is_xml_response
end

Instance Method Details

#_call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rack/stripper.rb', line 19

def _call(env)
  status, headers, response = @app.call(env)

  if status != 200
    return [status, headers, response]
  end

  if headers.has_key?('Content-Type')
    self.is_xml_response = !headers['Content-Type'].match(/xml/).nil?
  end

  if response.respond_to?(:body=)
    response.body = process_body(response.body)
    if headers.has_key?('Content-Length')
      headers['Content-Length'] = response.body.bytesize
    end
  end

  [status, headers, response]
end

#call(env) ⇒ Object



15
16
17
# File 'lib/rack/stripper.rb', line 15

def call(env)
  dup._call(env)
end