Class: CopyForAi::Middleware
- Inherits:
-
Object
- Object
- CopyForAi::Middleware
- Defined in:
- lib/copy_for_ai/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
7 8 9 |
# File 'lib/copy_for_ai/middleware.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 27 |
# File 'lib/copy_for_ai/middleware.rb', line 11 def call(env) status, headers, response = @app.call(env) # Only modify error responses (4xx and 5xx) with HTML content if error_response?(status) && html_response?(headers) body = extract_body(response) # Check if this is a Rails debug error page if rails_error_page?(body) modified_body = ContentInjector.inject(body) headers["Content-Length"] = modified_body.bytesize.to_s response = [modified_body] end end [status, headers, response] end |