Skip to content

Instantly share code, notes, and snippets.

@mipearson
Created January 1, 2013 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mipearson/4430598 to your computer and use it in GitHub Desktop.
Save mipearson/4430598 to your computer and use it in GitHub Desktop.
module Rack
class EnforceValidEncoding
def initialize app
@app = app
end
def call env
full_path = (env.fetch('PATH_INFO', '') + env.fetch('QUERY_STRING', ''))
if full_path.valid_encoding? && Rack::Utils.unescape(full_path).valid_encoding?
@app.call env
else
[400, {'Content-Type'=>'text/plain'}, ['Bad Request']]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment