permanent_not_found 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/lib/permanent_not_found.rb +11 -6
- data/lib/permanent_not_found/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7829c38792957ea0382df98ac076c296e1aeb683
|
4
|
+
data.tar.gz: e930cba9dfa85e20bc75a11bed4667bb95845530
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f18f11133e9be98414db38ba9b1535ecd6e0e6305be5cbcc98648359532471ce8b1b3d523dbfa6e1444e8a6094b5ee97fe937df9c4a67308fe84fdc69131cc6
|
7
|
+
data.tar.gz: 59f8a4a2628f42a739ccca7237407f157c756dcdef939dc8e1c7c9500fa3adce4c9a83e53755b45b28a5b39cb5c41cea9148987fb279a6f20ddf87dab319c54a
|
data/README.md
CHANGED
@@ -37,7 +37,11 @@ run Rack::Lobster.new
|
|
37
37
|
# config/application.rb
|
38
38
|
require 'permanent_not_found'
|
39
39
|
content = Rails.root.join('public', '404.html').read.freeze
|
40
|
-
config.middleware.insert_before(
|
40
|
+
config.middleware.insert_before(
|
41
|
+
Rack::Rewrite, PermanentNotFound, content: content,
|
42
|
+
paths: ['/wp-content', '/phpmyadmin'],
|
43
|
+
pattern: [/^legacyroute\/.*/, /\.swf$/]
|
44
|
+
)
|
41
45
|
```
|
42
46
|
|
43
47
|
## Development
|
data/lib/permanent_not_found.rb
CHANGED
@@ -4,15 +4,16 @@ require "set"
|
|
4
4
|
class PermanentNotFound
|
5
5
|
CONTENT = '404 Not Found'.freeze
|
6
6
|
|
7
|
-
def initialize(app, content: CONTENT, paths: [])
|
8
|
-
@app
|
7
|
+
def initialize(app, content: CONTENT, paths: [], pattern: [])
|
8
|
+
@app = app
|
9
9
|
@content = content
|
10
|
-
@paths
|
10
|
+
@paths = Set.new(paths)
|
11
|
+
@pattern = Regexp.union(pattern)
|
11
12
|
end
|
12
13
|
|
13
14
|
def call(env)
|
14
|
-
if
|
15
|
-
|
15
|
+
if permanent_redirected?(env['PATH_INFO'].downcase)
|
16
|
+
response_with_404
|
16
17
|
else
|
17
18
|
@app.call(env)
|
18
19
|
end
|
@@ -20,7 +21,11 @@ class PermanentNotFound
|
|
20
21
|
|
21
22
|
private
|
22
23
|
|
23
|
-
def
|
24
|
+
def permanent_redirected?(path)
|
25
|
+
@paths.include?(path) || @pattern =~ path
|
26
|
+
end
|
27
|
+
|
28
|
+
def response_with_404
|
24
29
|
[404, { 'Content-Type' => 'text/html', 'Content-Length' => @content.size.to_s }, [@content]]
|
25
30
|
end
|
26
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: permanent_not_found
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Spickermann
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-06-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.6.
|
96
|
+
rubygems_version: 2.6.12
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: Tiny little Rack middleware to answer a configured set of path's with a HTTP
|