laws_of_robots_txt 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/laws_of_robots_txt.gemspec +24 -0
- data/lib/laws_of_robots_txt.rb +4 -0
- data/lib/laws_of_robots_txt/middleware.rb +28 -0
- data/lib/laws_of_robots_txt/railtie.rb +7 -0
- data/lib/laws_of_robots_txt/version.rb +3 -0
- data/test/fixtures/www.example.com.txt +2 -0
- data/test/laws_of_robots_txt_test.rb +81 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e74143066e8e5af59911de84728b59ddcd84d119
|
4
|
+
data.tar.gz: a46779eaa0dd40807372c4dbe194e99be471397c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed82e0e6120a5915174814bc5aa7cac722f555b515510495cacca922698edd6be1e9aba62ac3b191581c86236591496e11532a511a27892b66961bae29e23caf
|
7
|
+
data.tar.gz: 014eba62fac7d4b33c4b616a15ad3d91b4718c4b608fe0f8a885fbe97438381d9316174243a4520c783094f313b4697ebb91d4b6d3b6cbe35d72dad3b0acbcfc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 John Hawthorn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# LawsOfRobotsTxt
|
2
|
+
|
3
|
+
1. A robot may not index staging servers
|
4
|
+
2. A robot must obey the sitemap
|
5
|
+
3. A robot may not injure SEO or, through inaction, cause SEO to come to harm.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'laws_of_robots_txt'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Be sure to remove `public/robots.txt`, if it exists
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
LawsOfRobotsTxt installs a rack middleware into your application which renders
|
22
|
+
a different `/robots.txt` based on the request's domain.
|
23
|
+
|
24
|
+
It looks in `config/robots/` for a file named `<DOMAIN>.txt`, for example,
|
25
|
+
`config/robots/www.example.com.txt`. A server restart is required to pick up
|
26
|
+
changes.
|
27
|
+
|
28
|
+
If no file exists for the requests domain, it renders a default
|
29
|
+
|
30
|
+
```
|
31
|
+
# Robots not allowed on this domain
|
32
|
+
User-Agent: *
|
33
|
+
Disallow: /
|
34
|
+
```
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
1. Fork it ( http://github.com/freerunningtech/laws_of_robots_txt/fork )
|
39
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
40
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
41
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
42
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'laws_of_robots_txt/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "laws_of_robots_txt"
|
8
|
+
spec.version = LawsOfRobotsTxt::VERSION
|
9
|
+
spec.authors = ["John Hawthorn"]
|
10
|
+
spec.email = ["john@freerunningtechnologies.com"]
|
11
|
+
spec.summary = %q{Rack middleware providing a per-domain robots.txt}
|
12
|
+
spec.description = "1. A robot may not index staging servers\n2. A robot must obey the sitemap\n3. A robot may not injure SEO or, through inaction, cause SEO to come to harm."
|
13
|
+
spec.homepage = "https://github.com/freerunningtech/laws_of_robots_txt"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rack-test"
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module LawsOfRobotsTxt
|
4
|
+
class Middleware
|
5
|
+
def initialize app, config_dir
|
6
|
+
@app = app
|
7
|
+
@robots_files = Hash[Dir[File.join(config_dir, "*.txt")].map do |filename|
|
8
|
+
domain = File.basename(filename, ".txt")
|
9
|
+
[domain, File.read(filename)]
|
10
|
+
end]
|
11
|
+
end
|
12
|
+
def call env
|
13
|
+
if env["PATH_INFO"] == "/robots.txt"
|
14
|
+
domain = env["SERVER_NAME"]
|
15
|
+
[200, {"Content-Type" => "text/plain"}, [robots_txt(domain)]]
|
16
|
+
else
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
def robots_txt domain
|
21
|
+
if robot_string = @robots_files[domain]
|
22
|
+
robot_string
|
23
|
+
else
|
24
|
+
"# Robots not allowed on this domain\nUser-Agent: *\nDisallow: /\n"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
$:.unshift File.expand_path("../../lib/", __FILE__)
|
2
|
+
|
3
|
+
require 'rack/test'
|
4
|
+
require 'rack/lint'
|
5
|
+
require 'test/unit'
|
6
|
+
require 'laws_of_robots_txt'
|
7
|
+
|
8
|
+
class LawsOfRobotsTxtTest < Test::Unit::TestCase
|
9
|
+
include Rack::Test::Methods
|
10
|
+
|
11
|
+
class MockApp
|
12
|
+
attr_reader :called
|
13
|
+
def initialize
|
14
|
+
@called = false
|
15
|
+
end
|
16
|
+
def call env
|
17
|
+
@called = true
|
18
|
+
[200, {}, []]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def config_dir
|
23
|
+
File.expand_path("../fixtures/", __FILE__)
|
24
|
+
end
|
25
|
+
def mock_app
|
26
|
+
@mockapp ||= MockApp.new
|
27
|
+
end
|
28
|
+
def build_app
|
29
|
+
app = mock_app
|
30
|
+
app = Rack::Lint.new(app)
|
31
|
+
app = LawsOfRobotsTxt::Middleware.new(app, config_dir)
|
32
|
+
app = Rack::Lint.new(app)
|
33
|
+
app
|
34
|
+
end
|
35
|
+
def app
|
36
|
+
@app ||= build_app
|
37
|
+
end
|
38
|
+
def assert_status expected
|
39
|
+
assert_equal expected, @status
|
40
|
+
end
|
41
|
+
def assert_body expected
|
42
|
+
body_string = ''
|
43
|
+
@body.each{|b| body_string << b}
|
44
|
+
assert_equal body_string, expected
|
45
|
+
end
|
46
|
+
def assert_header name, expected
|
47
|
+
headers = Rack::Utils::HeaderHash.new(@headers)
|
48
|
+
assert_equal headers[name], expected
|
49
|
+
end
|
50
|
+
def make_request url
|
51
|
+
@status, @headers, @body = app.call(Rack::MockRequest.env_for(url))
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_requests_pass_through
|
55
|
+
make_request "http://www.example.com/foobar"
|
56
|
+
assert mock_app.called, "should pass through"
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_defined_robots
|
60
|
+
make_request "http://www.example.com/robots.txt"
|
61
|
+
assert !mock_app.called, "should not pass through"
|
62
|
+
|
63
|
+
assert_status 200
|
64
|
+
assert_header "Content-Type", "text/plain"
|
65
|
+
assert_body File.read("#{config_dir}/www.example.com.txt")
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_undefined_robots
|
69
|
+
make_request "http://www.example.net/robots.txt"
|
70
|
+
assert !mock_app.called, "should not pass through"
|
71
|
+
|
72
|
+
assert_status 200
|
73
|
+
assert_header "Content-Type", "text/plain"
|
74
|
+
assert_body <<EOS
|
75
|
+
# Robots not allowed on this domain
|
76
|
+
User-Agent: *
|
77
|
+
Disallow: /
|
78
|
+
EOS
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: laws_of_robots_txt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Hawthorn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rack-test
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: |-
|
56
|
+
1. A robot may not index staging servers
|
57
|
+
2. A robot must obey the sitemap
|
58
|
+
3. A robot may not injure SEO or, through inaction, cause SEO to come to harm.
|
59
|
+
email:
|
60
|
+
- john@freerunningtechnologies.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- laws_of_robots_txt.gemspec
|
71
|
+
- lib/laws_of_robots_txt.rb
|
72
|
+
- lib/laws_of_robots_txt/middleware.rb
|
73
|
+
- lib/laws_of_robots_txt/railtie.rb
|
74
|
+
- lib/laws_of_robots_txt/version.rb
|
75
|
+
- test/fixtures/www.example.com.txt
|
76
|
+
- test/laws_of_robots_txt_test.rb
|
77
|
+
homepage: https://github.com/freerunningtech/laws_of_robots_txt
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.1.11
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Rack middleware providing a per-domain robots.txt
|
101
|
+
test_files:
|
102
|
+
- test/fixtures/www.example.com.txt
|
103
|
+
- test/laws_of_robots_txt_test.rb
|