Class: Rack::Pagelime
- Inherits:
-
Object
- Object
- Rack::Pagelime
- Extended by:
- ClassMethods
- Includes:
- ClassMethods, Utils
- Defined in:
- lib/rack/pagelime.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- ENV_KEYS =
{ :toggle_processing => "pagelime.toggle_processing" }
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Pagelime
constructor
A new instance of Pagelime.
Methods included from ClassMethods
disable_processing_for_request, enable_processing_for_request, handle_publish_callback, handle_route, handle_status_check, processing_enabled_for_request?
Constructor Details
Instance Method Details
#call(env) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rack/pagelime.rb', line 88 def call(env) app_resp = @app.call(env) req = Rack::Request.new(env) resp = handle_route(req) # only process original output if routing wasn't handled unless resp status, headers, response = app_resp ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Headers: #{headers}" ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Status: #{status.inspect}" ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Response: #{response}" if status == 200 && headers["Content-Type"].to_s.include?("text/html") && processing_enabled_for_request?(req) html = "" response.each{|part| html << part} ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing For Path: #{req.path}" ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing Body (size:#{html.length})" ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Processing Body: #{html.inspect}" html = ::Pagelime.process_page(html, req.path) headers['content-length'] = html.length.to_s body = [html] else ::Pagelime.logger.debug "PAGELIME CMS RACK PLUGIN: Not touching this request" body = response end resp = [status, headers, body] end resp end |