Class: Rack::LoadSpeed
- Inherits:
-
Object
- Object
- Rack::LoadSpeed
- Defined in:
- lib/load_speed.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ LoadSpeed
constructor
A new instance of LoadSpeed.
Constructor Details
#initialize(app) ⇒ LoadSpeed
Returns a new instance of LoadSpeed.
3 4 5 |
# File 'lib/load_speed.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/load_speed.rb', line 7 def call(env) env.delete("HTTP_IF_NONE_MATCH") status, headers, response = @app.call(env) if status == 200 && headers["Content-Type"] =~ /text\/html|application\/xhtml\+xml/ body = "" response.each {|part| body << part} index = body.rindex("</body>") if index body.insert(index, performance_code) # # handle body w/ UTF8 characters for Ruby 1.9+ to avoid Rack::Lint::LintError # headers["Content-Length"] = (body.respond_to?(:bytesize) ? body.bytesize : body.length).to_s response = [body] end end [status, headers, response] end |