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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96eff0977deeefeed71dc2a419d73539c4f9b227
4
- data.tar.gz: 144217b6913f978420144878f86743c1b811094b
3
+ metadata.gz: 7829c38792957ea0382df98ac076c296e1aeb683
4
+ data.tar.gz: e930cba9dfa85e20bc75a11bed4667bb95845530
5
5
  SHA512:
6
- metadata.gz: bcb1c45b571093beef314b6ed405771e2d76f96f6caa86062e54309c2b8f711bd01b5e4647538ee719905d52769f473a80852667c5922117284afe65944fda49
7
- data.tar.gz: '0685a965364b2b8abf48a156241896f87a96637fa2962c3b0f30b450e02038f815a2f9aa715ffb9b33623792852213ce75cf60b6b094d2bf276aeec529e9e9ba'
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(Rack::Rewrite, PermanentNotFound, content: content, paths: ['/wp-content', '/phpmyadmin'])
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
@@ -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 = app
7
+ def initialize(app, content: CONTENT, paths: [], pattern: [])
8
+ @app = app
9
9
  @content = content
10
- @paths = Set.new(paths)
10
+ @paths = Set.new(paths)
11
+ @pattern = Regexp.union(pattern)
11
12
  end
12
13
 
13
14
  def call(env)
14
- if @paths.include?(env['PATH_INFO'].downcase)
15
- response
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 response
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
@@ -1,3 +1,3 @@
1
1
  class PermanentNotFound
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  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.0
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-05-30 00:00:00.000000000 Z
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.10
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