notsofast 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 585486e4b0d5b41dc84fce9b329acf2ef27149e9
4
+ data.tar.gz: 06e5f5a8d73a70e14cf5bc5ae7ec04e2ba7b1f56
5
+ SHA512:
6
+ metadata.gz: a01505be72dd535c220d00885ea3e14b01ae63327e5904191c90ecac7de79f3b491de71988303a5b4fb82ffc521de411b5aa22110817522cb1f730fb80007733
7
+ data.tar.gz: 19fef32d29cee467b744367ccc043c7d7b15a8fe348417c8002d7381b117e2f33e62bd942c1b2ebcd4a953d080bdfe36e54fb9752a9b5979705f9ab0017d0001
@@ -6,46 +6,59 @@ module Notsofast
6
6
  @request_limit = 100
7
7
  @response_types = ["text/html"]
8
8
  @limit_expiry = 60
9
+ @notify = Proc.new{|ip, env| }
10
+
11
+ def self.configure(&block)
12
+ yield self
13
+ end
9
14
 
10
15
  def self.whitelist=(value)
11
16
  @whitelist = value
12
17
  end
13
-
18
+
14
19
  def self.blacklist=(value)
15
20
  @blacklist = value
16
21
  end
17
-
22
+
18
23
  def self.request_limit=(value)
19
24
  @request_limit = value
20
25
  end
21
-
26
+
22
27
  def self.response_types=(value)
23
28
  @response_types = value
24
29
  end
25
-
30
+
26
31
  def self.limit_expiry=(value)
27
32
  @limit_expiry = value
28
33
  end
29
-
34
+
35
+ def self.notify=(value)
36
+ @notify = value
37
+ end
38
+
30
39
  def self.whitelist
31
40
  @whitelist
32
41
  end
33
-
42
+
34
43
  def self.blacklist
35
44
  @blacklist
36
45
  end
37
-
46
+
38
47
  def self.request_limit
39
48
  @request_limit
40
49
  end
41
-
50
+
42
51
  def self.response_types
43
52
  @response_types
44
53
  end
45
-
54
+
46
55
  def self.limit_expiry
47
56
  @limit_expiry
48
57
  end
49
-
58
+
59
+ def self.notify
60
+ @notify
61
+ end
62
+
50
63
  end
51
64
  end
@@ -18,11 +18,14 @@ module Notsofast
18
18
  def call(env)
19
19
  status, headers, response = @app.call(env)
20
20
 
21
+ puts "checking..."
22
+
21
23
  if timestamp - @connections_timestamp > Notsofast::Config.limit_expiry
22
24
  @connections_timestamp = timestamp
23
25
  @connections = {}
24
26
  end
25
27
 
28
+
26
29
  ip_address = remote_ip(env)
27
30
 
28
31
  unless Notsofast::Config.whitelist.include?(ip_address)
@@ -41,6 +44,10 @@ module Notsofast
41
44
  end
42
45
 
43
46
  if @connections[ip_address] > Notsofast::Config.request_limit
47
+
48
+ puts "Rate Limiting!!!"
49
+ Notsofast::Config.notify.call(ip_address, env)
50
+
44
51
  response = Rack::Response.new
45
52
  response.write 'Rate Limited'
46
53
  response.status = 429
@@ -49,6 +56,7 @@ module Notsofast
49
56
  end
50
57
  end
51
58
  end
59
+ puts "done"
52
60
  [status, headers, response]
53
61
  end
54
62
  end
@@ -1,3 +1,3 @@
1
1
  module Notsofast
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,56 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notsofast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
5
- prerelease:
4
+ version: 0.0.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Stewart McKee
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-27 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.3'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.3'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
- description: ! 'Rate limiting gem based on IP address '
41
+ description: 'Rate limiting gem based on IP address '
47
42
  email:
48
43
  - stewart@theizone.co.uk
49
44
  executables: []
50
45
  extensions: []
51
46
  extra_rdoc_files: []
52
47
  files:
53
- - .gitignore
48
+ - ".gitignore"
54
49
  - Gemfile
55
50
  - LICENSE.txt
56
51
  - README.md
@@ -64,26 +59,25 @@ files:
64
59
  homepage: http://github.com/stewartmckee/notsofast
65
60
  licenses:
66
61
  - MIT
62
+ metadata: {}
67
63
  post_install_message:
68
64
  rdoc_options: []
69
65
  require_paths:
70
66
  - lib
71
67
  required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
68
  requirements:
74
- - - ! '>='
69
+ - - ">="
75
70
  - !ruby/object:Gem::Version
76
71
  version: '0'
77
72
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
73
  requirements:
80
- - - ! '>='
74
+ - - ">="
81
75
  - !ruby/object:Gem::Version
82
76
  version: '0'
83
77
  requirements: []
84
78
  rubyforge_project:
85
- rubygems_version: 1.8.24
79
+ rubygems_version: 2.2.2
86
80
  signing_key:
87
- specification_version: 3
81
+ specification_version: 4
88
82
  summary: Rate limiting gem based on IP address
89
83
  test_files: []