class Rack::EnforceValidEncoding
Ensure that the path and query string presented to the application contains only valid characters. If the validation fails, then a 400 Bad Request response is returned immediately.
Requires: Ruby 1.9
Public Class Methods
new(app)
click to toggle source
# File lib/rack/contrib/enforce_valid_encoding.rb 11 def initialize app 12 @app = app 13 end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/contrib/enforce_valid_encoding.rb 15 def call env 16 full_path = (env.fetch('PATH_INFO', '') + env.fetch('QUERY_STRING', '')) 17 if full_path.force_encoding("US-ASCII").valid_encoding? && 18 Rack::Utils.unescape(full_path).valid_encoding? 19 @app.call env 20 else 21 [400, {'Content-Type'=>'text/plain'}, ['Bad Request']] 22 end 23 end