Sha256: a6e62001386d2dcc581320b72cc8a4c9d734351e544f02330bda8074040fdb3c
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module Rack module MockJson class Middleware def initialize(app, config_file_path: nil) @app = app @mock = Rack::MockJson::Mock.new(config_file_path) end 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 private def request_path "#{@request.request_method} #{@request.path_info}" end def mock_element_index @request.params["mock_element_index"] ? @request.params["mock_element_index"].to_i : nil end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rack-mock_json-0.0.3 | lib/rack/mock_json/middleware.rb |