Forked from mipearson/rack_enforce_valid_encoding.rb
Created
January 1, 2013 22:37
-
-
Save juliocesar/4430602 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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