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 Instance Methods

call(env) click to toggle source
# File lib/rack/contrib/enforce_valid_encoding.rb, line 13
def call env
  full_path = (env.fetch('PATH_INFO', '') + env.fetch('QUERY_STRING', ''))
  if full_path.force_encoding("US-ASCII").valid_encoding? &&
     Rack::Utils.unescape(full_path).valid_encoding?
    @app.call env
  else
    [400, {'Content-Type'=>'text/plain'}, ['Bad Request']]
  end
end

Public Class Methods

new(app) click to toggle source
# File lib/rack/contrib/enforce_valid_encoding.rb, line 9
def initialize app
  @app = app
end