Sha256: f89f1a80c6e853414b748fea46a63a9df2c5e2c45ee8e98a2d4435d02c757c91
Contents?: true
Size: 578 Bytes
Versions: 1
Compression:
Stored size: 578 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.dup.force_encoding(Encoding::UTF_8).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.2 | lib/rack/encoding_guard/reject_strategy.rb |