Skip to content

Instantly share code, notes, and snippets.

@redinger
Created October 16, 2009 22:31
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 redinger/212123 to your computer and use it in GitHub Desktop.
Save redinger/212123 to your computer and use it in GitHub Desktop.
class NoSlashdot
def initialize(app, options = {})
@app = app
@options = options
@options[:redirect] ||= 'http://slashdot.org'
end
def call(env)
slashdot_sent_ya?(env) ? kick_it : @app.call(env)
end
private
def slashdot_sent_ya?(env)
if env['HTTP_REFERER']
is_slashdot?(env['HTTP_REFERER']) and @options[:redirect] != env['PATH_INFO']
end
end
def is_slashdot?(referer_string)
referer_string.match(/slashdot.org/) ? true : false
end
def kick_it
[301, {'Location' => @options[:redirect]}, 'Slashdotting is fail']
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment