rack-noslashdot 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.markdown +24 -0
- data/Rakefile +55 -0
- data/lib/no_slashdot.rb +26 -0
- data/test/rack-noslashdot_test.rb +16 -0
- data/test/test_helper.rb +10 -0
- metadata +64 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Christopher Redinger
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# rack-noslashdot
|
2
|
+
|
3
|
+
rack-noslashdot will redirect anyone who has been refered by slashdot (and doesn't mask their HTTP_REFERER header)
|
4
|
+
|
5
|
+
# usage
|
6
|
+
|
7
|
+
just
|
8
|
+
|
9
|
+
config.middleware.use "NoSlashdot", :redirect => 'http://slashdot.org'
|
10
|
+
|
11
|
+
or let the default kick in
|
12
|
+
|
13
|
+
config.middleware.use "NoSlashdot"
|
14
|
+
|
15
|
+
# license
|
16
|
+
|
17
|
+
Copyright (c) 2009 Christopher Redinger. See LICENSE for details.
|
18
|
+
|
19
|
+
# thanks
|
20
|
+
This is just a play on Julio Cesar's NoIE middleware.
|
21
|
+
http://github.com/juliocesar/rack-noie
|
22
|
+
|
23
|
+
in response to Peter Cooper's tweet
|
24
|
+
http://twitter.com/peterc/status/4926493168
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rack-noslashdot"
|
8
|
+
gem.summary = %Q{Redirect slashdot referers}
|
9
|
+
gem.description = %Q{Because sometimes you just want to be left alone}
|
10
|
+
gem.email = "redinger@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/redinger/rack-noslashdot"
|
12
|
+
gem.authors = ["Christopher Redinger"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
Rake::TestTask.new(:test) do |test|
|
21
|
+
test.libs << 'lib' << 'test'
|
22
|
+
test.pattern = 'test/**/*_test.rb'
|
23
|
+
test.verbose = true
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
require 'rcov/rcovtask'
|
28
|
+
Rcov::RcovTask.new do |test|
|
29
|
+
test.libs << 'test'
|
30
|
+
test.pattern = 'test/**/*_test.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
33
|
+
rescue LoadError
|
34
|
+
task :rcov do
|
35
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
task :test => :check_dependencies
|
40
|
+
|
41
|
+
task :default => :test
|
42
|
+
|
43
|
+
require 'rake/rdoctask'
|
44
|
+
Rake::RDocTask.new do |rdoc|
|
45
|
+
if File.exist?('VERSION')
|
46
|
+
version = File.read('VERSION')
|
47
|
+
else
|
48
|
+
version = ""
|
49
|
+
end
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "rack-noslashdot #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/lib/no_slashdot.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class NoSlashdot
|
2
|
+
def initialize(app, options = {})
|
3
|
+
@app = app
|
4
|
+
@options = options
|
5
|
+
@options[:redirect] ||= 'http://slashdot.org'
|
6
|
+
end
|
7
|
+
|
8
|
+
def call(env)
|
9
|
+
slashdot_sent_ya?(env) ? kick_it : @app.call(env)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def slashdot_sent_ya?(env)
|
14
|
+
if env['HTTP_REFERER']
|
15
|
+
is_slashdot?(env['HTTP_REFERER']) and @options[:redirect] != env['PATH_INFO']
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def is_slashdot?(referer_string)
|
20
|
+
referer_string.match(/slashdot.org/) ? true : false
|
21
|
+
end
|
22
|
+
|
23
|
+
def kick_it
|
24
|
+
[301, {'Location' => @options[:redirect]}, 'Fail browser is fail']
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class NoslashdotTest < Test::Unit::TestCase
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
def app
|
7
|
+
NoSlashdot.new(lambda { |env| [200, {}, "You've been slashdotted!"] }, :redirect => 'http://slashdot.org')
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_redirects_to_where_it_should_if_slashdot
|
11
|
+
get '/', {}, "HTTP_REFERER" => 'www.slashdot.org'
|
12
|
+
assert last_response.redirect?
|
13
|
+
follow_redirect!
|
14
|
+
assert_equal 'http://slashdot.org/', last_request.url
|
15
|
+
end
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-noslashdot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Christopher Redinger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-16 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Because sometimes you just want to be left alone
|
17
|
+
email: redinger@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.markdown
|
25
|
+
files:
|
26
|
+
- .document
|
27
|
+
- .gitignore
|
28
|
+
- LICENSE
|
29
|
+
- README.markdown
|
30
|
+
- Rakefile
|
31
|
+
- lib/no_slashdot.rb
|
32
|
+
- test/rack-noslashdot_test.rb
|
33
|
+
- test/test_helper.rb
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: http://github.com/redinger/rack-noslashdot
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options:
|
40
|
+
- --charset=UTF-8
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 1.3.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Redirect slashdot referers
|
62
|
+
test_files:
|
63
|
+
- test/rack-noslashdot_test.rb
|
64
|
+
- test/test_helper.rb
|