da99_rack_protect 2.0.2 → 3.0.0

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: b2e6ef07cf45beee6e0e040c99df3c5f63a6c6f1
4
- data.tar.gz: 551bfa85f643a26860b241a386e1ed752b6426a5
3
+ metadata.gz: a61fb2c3ed3d0700440b6aaeb8d9fceb2c5a4423
4
+ data.tar.gz: 940af48f2d8700ef87391437eadbfe1079b84956
5
5
  SHA512:
6
- metadata.gz: 50fbd480139dcc53acd2b97106be75f9a823702c8926e9861f5b581facc4490488ae89cfae7012b3df76eb6bd4beeedeefcd07fc8543323c286c1ddaddd98de5
7
- data.tar.gz: dca52f395017f3b6312d0064c8dd2520e01fd2d8964dbcb8a2473ab7dfb8209bed60ad45d509ad72272044e8da1eca4dbaf6194886f3b5ca6d1b6dd80ea57559
6
+ metadata.gz: 28ea632e1cd7d22cc090efc3ccc9753a2c149dcaee72d06d65f807b0fd7b1217ba19041cf98ac6125bf0c8b5757805284364b746c6a4fd85a47ff79f0a30f059
7
+ data.tar.gz: f0220ff10afed1eaeb4650c218b956ff5dcab3f15dfaa0a0dfe7a781c1949b2bff6cc04ebbbbccf3df7eec5c7beab15106b9dd74a802d83616337659bcccd0a5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.2
1
+ 3.0.0
@@ -3,7 +3,6 @@ require 'rack/protection'
3
3
 
4
4
  class Da99_Rack_Protect
5
5
 
6
- HOSTS = []
7
6
  DA99 = self
8
7
 
9
8
  # =================================================================
@@ -63,31 +62,6 @@ class Da99_Rack_Protect
63
62
 
64
63
  class << self
65
64
 
66
- def config *args
67
- yield(self) if block_given?
68
- case args.length
69
- when 0
70
- # do nothing
71
-
72
- when 2
73
-
74
- case args.first
75
-
76
- when :host
77
- HOSTS.concat args.last
78
-
79
- else
80
- fail "Unknown args: #{args.inspect}"
81
-
82
- end # === case
83
-
84
- else
85
- fail "Unknown args: #{args.inspect}"
86
- end # === case
87
-
88
- self
89
- end # === def config
90
-
91
65
  def redirect new, code = 301
92
66
  res = Rack::Response.new
93
67
  res.redirect new, code
@@ -107,6 +81,10 @@ class Da99_Rack_Protect
107
81
  end # === class self
108
82
 
109
83
  def initialize main_app
84
+ @configs = configs = {:hosts=>[]}
85
+
86
+ yield(self) if block_given?
87
+
110
88
  @app = Rack::Builder.new do
111
89
 
112
90
  use Rack::Lint
@@ -120,7 +98,12 @@ class Da99_Rack_Protect
120
98
  }
121
99
 
122
100
  Names.each { |name|
123
- use Da99_Rack_Protect.const_get(name)
101
+ case name
102
+ when :Ensure_Host
103
+ use Da99_Rack_Protect.const_get(name), *(configs[:hosts])
104
+ else
105
+ use Da99_Rack_Protect.const_get(name)
106
+ end
124
107
  }
125
108
 
126
109
  if ENV['IS_DEV']
@@ -130,8 +113,21 @@ class Da99_Rack_Protect
130
113
 
131
114
  run main_app
132
115
  end
116
+
117
+ @configs[:hosts].freeze
133
118
  end
134
119
 
120
+ def config settings, *args
121
+ case settings
122
+ when :host
123
+ @configs[:hosts].concat args
124
+ else
125
+ fail "Unknown args: #{args.inspect}"
126
+ end # === case
127
+
128
+ self
129
+ end # === def config
130
+
135
131
  def call env
136
132
  @app.call env
137
133
  end
@@ -3,30 +3,30 @@ class Da99_Rack_Protect
3
3
 
4
4
  class Ensure_Host
5
5
 
6
- SERVER_NAME = 'SERVER_NAME'
6
+ SERVER_NAME = 'SERVER_NAME'.freeze
7
7
  LOCALHOST = /\A(localhost|127\.0\.0\.1)\z/
8
- HTT_HOST = 'HTTP_HOST'
8
+ HTT_HOST = 'HTTP_HOST'.freeze
9
9
 
10
- def initialize new_app
10
+ def initialize new_app, *hosts
11
11
  @app = new_app
12
+ @hosts = hosts
12
13
  end
13
14
 
14
15
  def call e
15
- hosts = Da99_Rack_Protect::HOSTS
16
16
  name = e[SERVER_NAME]
17
17
  host = e[HTT_HOST]
18
18
 
19
- is_valid = hosts.include?(name)
19
+ is_valid = @hosts.include?(name)
20
20
 
21
21
  if !is_valid
22
- is_local = hosts.include?(:localhost) && name[LOCALHOST]
22
+ is_local = @hosts.include?(:localhost) && name[LOCALHOST]
23
23
  is_valid = is_local
24
24
  end
25
25
 
26
26
  is_match = host[/\A#{name}(:\d+)?\z/]
27
27
 
28
28
  return @app.call(e) if is_valid && is_match
29
- Da99_Rack_Protect.response 444, :text, 'Unknown error.'
29
+ Da99_Rack_Protect.response 444, :text, 'Invalid host specified by client.'
30
30
  end
31
31
 
32
32
  end # === class Ensure_Host
@@ -2,9 +2,9 @@
2
2
  require 'cuba'
3
3
  require 'da99_rack_protect'
4
4
 
5
- Cuba.use Da99_Rack_Protect.config { |c|
6
- c.config :host, [:localhost, 'da99_sample.com']
7
- }
5
+ Cuba.use Da99_Rack_Protect do |mid|
6
+ mid.config :host, :localhost, 'da99_sample.com'
7
+ end
8
8
 
9
9
  if ENV['IS_DEV']
10
10
  Cuba.use Rack::ShowExceptions
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: da99_rack_protect
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - da99
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2015-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack-protection