Sha256: babf16140dc2e83649857fea90db043343dc3473a388bb0436ec0a3f11617be4

Contents?: true

Size: 908 Bytes

Versions: 1

Compression:

Stored size: 908 Bytes

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?

        [
          mock_element.status,
          {
            "Content-Type"           => "application/json",
            "Content-Length"         =>  mock_element.content.bytesize.to_s,
            "X-XSS-Protection"       => "1; mode=block",
            "X-Content-Type-Options" => "nosniff",
            "X-Frame-Options"        => "SAMEORIGIN"
          },
          [mock_element.content]
        ]
      end

      private

        def request_path
          "#{@request.request_method} #{@request.path_info}"
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-mock_json-0.0.2 lib/rack/mock_json/middleware.rb