rate_limit_mock_server 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +28 -6
- data/bin/rate_limit_mock_server +17 -4
- data/lib/rate_limit_mock_server/server.rb +1 -1
- data/lib/rate_limit_mock_server/version.rb +1 -1
- data/lib/rate_limit_mock_server.rb +3 -2
- data.tar.gz.sig +2 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21be3ae474578dff1b2becba7daaf8467cdc862bd6bc9c3b0f7e05431f0a1edf
|
4
|
+
data.tar.gz: ec5b32fdab8d805aada27badd8d42d783765e873f20fa955ddc6faa6aa67dcf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c760fc11117abec0e5e8953d1baf6d319a4dc07dce41626322a534a3d6ad83cd8191e217adc00294e101436c4a7c03e3ec32ae5bcdeff605f52eb0aeabbc6e7
|
7
|
+
data.tar.gz: b6c90674ed7fb5977728a70d5bc6713e8e0543452761b4cdb9868a44ad51734cfcdf7eef1b70cdbfcef84abfd26d255d3d0a6bca9da61257242742cac4441684
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# RateLimitMockServer
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
A mock server for testing rate limits.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
@@ -21,12 +19,26 @@ Or install it yourself as:
|
|
21
19
|
$ gem install rate_limit_mock_server
|
22
20
|
|
23
21
|
## Usage
|
22
|
+
Run the server in a shell:
|
23
|
+
```sh
|
24
|
+
# On default port: 4567
|
25
|
+
$ rate_limit_mock_server
|
26
|
+
|
27
|
+
# Or specify the port with
|
28
|
+
$ rate_limit_mock_server --port= 3000
|
29
|
+
# Or
|
30
|
+
$ rate_limit_mock_server -p 3000
|
31
|
+
```
|
32
|
+
|
24
33
|
To start the server from code, do this:
|
25
34
|
```ruby
|
26
35
|
require 'rate_limit_mock_server`
|
27
36
|
|
28
|
-
# Start the server on port 4567 and block the current thread
|
37
|
+
# Start the server on the default port 4567 and block the current thread
|
29
38
|
RateLimitMockServer.start
|
39
|
+
|
40
|
+
# Or start the server on the specified port and block the current thread
|
41
|
+
RateLimitMockServer.start(port: 1337)
|
30
42
|
```
|
31
43
|
|
32
44
|
Note, If you don't want the server to block the current thread, you can instead spawn a new thread for the server.
|
@@ -34,7 +46,7 @@ Note, If you don't want the server to block the current thread, you can instead
|
|
34
46
|
require 'rate_limit_mock_server`
|
35
47
|
|
36
48
|
thread = Thread.new do
|
37
|
-
# Start the server on port 4567
|
49
|
+
# Start the server on port 4567
|
38
50
|
RateLimitMockServer.start
|
39
51
|
end
|
40
52
|
|
@@ -49,7 +61,17 @@ Note, If you don't want the server to block the current thread, you can instead
|
|
49
61
|
thread.join
|
50
62
|
```
|
51
63
|
|
52
|
-
The server
|
64
|
+
The server responds to the following routes:
|
65
|
+
- `GET /limit_test` - Returns a "429 Too Many Requests" response (only for showing how such a response look).
|
66
|
+
- `PUT /quit` - Stops the server.
|
67
|
+
- `GET /:rate_limit` - Rate limited resources where `:rate_limit` is an integer that specifies the rate limit.
|
68
|
+
|
69
|
+
The "main" route (`GET /:rate_limit`) can be used to test different rate limits simultaneously. E.g. requests to
|
70
|
+
`GET /5` will be limited at 5 rps, while requests to `GET /20` will be limited at 20 rps.
|
71
|
+
|
72
|
+
Note: `:rate_limit` must be an integer greater than or equal to `1`. I.e it's not possible to user rate limits lower than 1 rps.
|
73
|
+
|
74
|
+
The server can be stopped by either `RateLimitMockServer.quit!` or by sending a PUT request to `http://localhost:4567/quit`.
|
53
75
|
|
54
76
|
## Development
|
55
77
|
|
data/bin/rate_limit_mock_server
CHANGED
@@ -1,8 +1,21 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
$LOAD_PATH << File.expand_path('../lib/', __dir__)
|
5
|
+
|
6
6
|
require 'rate_limit_mock_server'
|
7
|
-
|
8
|
-
|
7
|
+
|
8
|
+
port = nil
|
9
|
+
pattern = /\A-(?:-port(?:=(\d)*)?|p)\Z/
|
10
|
+
index = ARGV.index do |arg|
|
11
|
+
next unless m = pattern.match(arg)
|
12
|
+
|
13
|
+
port = m[1] if m.size > 1
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
port ||= ARGV[index + 1] if index
|
18
|
+
port &&= port.to_i
|
19
|
+
port = nil if port&.zero?
|
20
|
+
|
21
|
+
RateLimitMockServer.start(port: port)
|
@@ -4,10 +4,11 @@ require 'rate_limit_mock_server/version'
|
|
4
4
|
require 'rate_limit_mock_server/server'
|
5
5
|
|
6
6
|
module RateLimitMockServer
|
7
|
-
def self.start
|
7
|
+
def self.start(port: nil)
|
8
|
+
Server.set :port, port if port
|
8
9
|
Server.run!
|
9
10
|
end
|
10
|
-
|
11
|
+
|
11
12
|
def self.quit!
|
12
13
|
Server.quit!
|
13
14
|
end
|
data.tar.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
N�M��z )���j�Vzt������lۛ��q�ҷ��Qm����u7�Z(A9-�}��8�#b�y�E��<�����~rE]��)6z�Dkah�2� �
|
2
|
+
��]L�7N�d�������k���c�8fڑ�{v_��p� �/��틥â��.Y�@U��l�E��i`ň+K�M~{*���R��ܳm\\�Zt!-�(��=�m�z��}�*���H�U��Խ�yU��P2�����hFZ�[ͧ
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rate_limit_mock_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sammy Henningsson
|
@@ -31,7 +31,7 @@ cert_chain:
|
|
31
31
|
hDgtXQiNH/WrZi6kriR8NgvZIZobYz4qKW9nAuVEa3qqegirIKi6BtcHr1pWrWt1
|
32
32
|
FDc=
|
33
33
|
-----END CERTIFICATE-----
|
34
|
-
date: 2022-04-
|
34
|
+
date: 2022-04-07 00:00:00.000000000 Z
|
35
35
|
dependencies:
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sinatra
|
metadata.gz.sig
CHANGED
Binary file
|