Class: Rack::MockJson::Middleware
- Inherits:
-
Object
- Object
- Rack::MockJson::Middleware
- Defined in:
- lib/rack/mock_json/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, config_file_path: nil) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(app, config_file_path: nil) ⇒ Middleware
Returns a new instance of Middleware.
4 5 6 7 |
# File 'lib/rack/mock_json/middleware.rb', line 4 def initialize(app, config_file_path: nil) @app = app @mock = Rack::MockJson::Mock.new(config_file_path) end |
Instance Method Details
#call(env) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rack/mock_json/middleware.rb', line 9 def call(env) @request = Rack::Request.new(env) mock_element = @mock.mock_element(request_path) return @app.call(env) if mock_element.nil? content = mock_element.pick_content(mock_element_index) [ mock_element.status, { "Content-Type" => "application/json", "Content-Length" => content.bytesize.to_s, "X-XSS-Protection" => "1; mode=block", "X-Content-Type-Options" => "nosniff", "X-Frame-Options" => "SAMEORIGIN" }, [content] ] end |