Created
October 16, 2009 22:31
-
-
Save redinger/212123 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
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