Class: ResponseAssembler::Middleware
- Inherits:
-
Object
- Object
- ResponseAssembler::Middleware
- Defined in:
- lib/response_assembler/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, error_message = "<p>Loading failed...</p>", content_types = ["text/html", "text/xhtml", "text/css", "text/csv", "text/plain"]) ⇒ Middleware
constructor
In Rails you could use: config.middleware.use “Rack::ResponseAssembler”, “Yo! Can’t load parts!”, [“text/html”] to change error message and content types array that filter gets run on.
Constructor Details
#initialize(app, error_message = "<p>Loading failed...</p>", content_types = ["text/html", "text/xhtml", "text/css", "text/csv", "text/plain"]) ⇒ Middleware
In Rails you could use: config.middleware.use “Rack::ResponseAssembler”, “Yo! Can’t load parts!”, [“text/html”] to change error message and content types array that filter gets run on.
40 41 42 43 44 45 46 |
# File 'lib/response_assembler/middleware.rb', line 40 def initialize(app, = "<p>Loading failed...</p>", content_types = ["text/html", "text/xhtml", "text/css", "text/csv", "text/plain"]) @app = app @content_types = content_types @error_message = end |
Instance Method Details
#call(env) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/response_assembler/middleware.rb', line 48 def call(env) @original_env = env.clone status, headers, response = @app.call(env) return [status, headers, response] unless is_allowed_content_type(headers["Content-Type"].to_s) response = [assemble_from_parts(response)] headers["Content-Length"] = response[0].size.to_s [status, headers, response] end |