redinger (owner)

Revisions

gist: 212123 Download_button fork
public
Public Clone URL: git://gist.github.com/212123.git
Embed All Files: show embed
rack-noslashdot.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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