Skip to content

Instantly share code, notes, and snippets.

@AlexWheeler
Created May 13, 2016 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexWheeler/603c59e1072fd3a222128eef5f9e8eb6 to your computer and use it in GitHub Desktop.
Save AlexWheeler/603c59e1072fd3a222128eef5f9e8eb6 to your computer and use it in GitHub Desktop.
require 'rack'
class RemoveBadWords
BAD_WORDS = %w(emacs).freeze
def initialize(app)
@app = app
end
def call(env)
req = Rack::Request.new(env)
remove_bad_words!(req)
@app.call(env)
end
private
def remove_bad_words!(req)
req.params.each do |k,v|
if BAD_WORDS.include?(v)
puts " Deleting 💩 #{v}💩"
req.delete_param(k)
end
end
end
end
class UpcaseAllTheThings
def initialize(app)
@app = app
end
def call(env)
req = Rack::Request.new(env)
req.params.each do |k,v|
puts "Upcasing #{v} -> #{v.upcase}"
req.update_param(k, v.upcase)
end
@app.call(env)
end
end
app = Rack::Builder.new do
use UpcaseAllTheThings
use RemoveBadWords
run proc { |env| ['200', {'Content-Type' => 'text/html'}, ["Params: #{Rack::Request.new(env).params}"]] }
end
run app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment