Sha256: d895c57b542f2330d57404af0f20d3e13c5ede08115fb141cbd277078c9d5f4a

Contents?: true

Size: 542 Bytes

Versions: 1

Compression:

Stored size: 542 Bytes

Contents

module Rack
  module EncodingGuard
    class RejectStrategy < Strategy
      DEFAULT_MESSAGE = 'Bad Request'

      def process(env)
        return bad_request_response if invalid_request?(env)
        yield
      end

      private

      def message
        options.fetch(:with, DEFAULT_MESSAGE)
      end

      def invalid_request?(env)
        Strategy::PROCESSIBLE_KEYS.any? do |key|
          !env[key].to_s.valid_encoding?
        end
      end

      def bad_request_response
        [400, {}, [message]]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-encoding_guard-0.1.1 lib/rack/encoding_guard/reject_strategy.rb