Class: Rack::Metadata
- Inherits:
-
Object
- Object
- Rack::Metadata
- Defined in:
- lib/rack/metadata.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Metadata
constructor
A new instance of Metadata.
Constructor Details
#initialize(app, options = {}) ⇒ Metadata
Returns a new instance of Metadata.
4 5 6 |
# File 'lib/rack/metadata.rb', line 4 def initialize(app, = {}) @app = app end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rack/metadata.rb', line 8 def call(env) env['rack.metadata'] = {} status, headers, response = @app.call(env) if headers['Content-Type'].to_s.include?('text/html') # Only update HTML bodies if env['rack.metadata'] body = "" response.each { |part| body << part } index = body.rindex("</head>") if index body.insert(index, env['rack.metadata'].map{|k,v| (k,v)}.join("")) headers["Content-Length"] = body.length.to_s response = [body] end end end [status, headers, response] end |