Created
May 13, 2016 13:12
-
-
Save AlexWheeler/603c59e1072fd3a222128eef5f9e8eb6 to your computer and use it in GitHub Desktop.
This file contains 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
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