Sha256: 5c9163a2867c97d668676765a3139d160fe34bcbe71fe5019b96e50d584ccac0

Contents?: true

Size: 671 Bytes

Versions: 2

Compression:

Stored size: 671 Bytes

Contents

# frozen_string_literal: true

module BreezyPDFLite
  # Rack Middleware for BreezyPDFLite
  # Determines if the request should be intercepted or not
  class Middleware
    def initialize(app, _options = {})
      @app = app
    end

    def call(env)
      if intercept?(env)
        Interceptor.new(@app, env).call
      else
        @app.call(env)
      end
    end

    private

    # Is this request applicable?
    def intercept?(env)
      env["REQUEST_METHOD"].match?(/get/i) && matching_uri?(env)
    end

    def matching_uri?(env)
      BreezyPDFLite.middleware_path_matchers.any? do |regex|
        env["REQUEST_URI"].match?(regex)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
breezy_pdf_lite-0.1.1 lib/breezy_pdf_lite/middleware.rb
breezy_pdf_lite-0.1.0 lib/breezy_pdf_lite/middleware.rb