Class: CustomTag::Middleware
- Inherits:
-
Object
- Object
- CustomTag::Middleware
- Defined in:
- lib/custom_tag/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
3 4 5 |
# File 'lib/custom_tag/middleware.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 |
# File 'lib/custom_tag/middleware.rb', line 7 def call(env) code, headers, response = @app.call(env) unless headers["Content-Type"]&.include?("text/html") return [code, headers, response] end response_body = if response.respond_to?(:body) response.body else response[0] end response_body = CustomTag.parse_and_replace(response_body) headers["Content-Length"] = response_body.bytesize.to_s [code, headers, [response_body]] end |