rack-berater 0.0.1 → 0.0.2
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
- data/lib/rack/berater/handler.rb +7 -1
- data/lib/rack/berater/version.rb +1 -1
- data/spec/handler_spec.rb +30 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a5812fba3c2523be30274bcc192d67ba7cebbb1d2b52dcc0ca403d69c39630c
|
4
|
+
data.tar.gz: 46152472d4af26a86e506a9150ff9c56743490707b630ecddc94beb0e63f7448
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '079407a6fd8d63c849809c972ef15739de09bd490c1e3a4046ae047dbba8b36cb7e5f0606c17b5e5a6a74ce8ec9fa95f61139afc3937a5c30643fe85ff59e91d'
|
7
|
+
data.tar.gz: 7d6ede65719ed13181c25aca35a48c941ee9c4777caa4f56eede0552b4acdc39d2989069659217327a0b3bc494d0c178b1ee1faa21e42f5c70dd4067f4fb077e
|
data/lib/rack/berater/handler.rb
CHANGED
@@ -5,6 +5,9 @@ module Rack
|
|
5
5
|
@app = app
|
6
6
|
@options = {
|
7
7
|
status_code: options.fetch(:status_code, 429),
|
8
|
+
headers: {
|
9
|
+
Rack::CONTENT_TYPE => "text/plain",
|
10
|
+
}.update(options.fetch(:headers, {})),
|
8
11
|
body: options.fetch(:body, true),
|
9
12
|
}
|
10
13
|
end
|
@@ -13,6 +16,7 @@ module Rack
|
|
13
16
|
@app.call(env)
|
14
17
|
rescue ::Berater::Overloaded => e
|
15
18
|
code = @options[:status_code]
|
19
|
+
|
16
20
|
body = case @options[:body]
|
17
21
|
when true
|
18
22
|
Rack::Utils::HTTP_STATUS_CODES[code]
|
@@ -26,9 +30,11 @@ module Rack
|
|
26
30
|
raise ArgumentError, "invalid :body option: #{@options[:body]}"
|
27
31
|
end
|
28
32
|
|
33
|
+
headers = body ? @options[:headers] : {}
|
34
|
+
|
29
35
|
[
|
30
36
|
code,
|
31
|
-
|
37
|
+
headers,
|
32
38
|
[ body ].compact,
|
33
39
|
]
|
34
40
|
end
|
data/lib/rack/berater/version.rb
CHANGED
data/spec/handler_spec.rb
CHANGED
@@ -11,8 +11,20 @@ describe Rack::Berater::Handler do
|
|
11
11
|
let(:response) { get "/" }
|
12
12
|
|
13
13
|
shared_examples "works nominally" do
|
14
|
-
it
|
15
|
-
|
14
|
+
it "has the correct status code" do
|
15
|
+
expect(response.status).to eq 200
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has the correct headers" do
|
19
|
+
expect(response.headers).to eq({
|
20
|
+
"Content-Type" => "text/plain",
|
21
|
+
"Content-Length" => "2",
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has the correct body" do
|
26
|
+
expect(response.body).to eq "OK"
|
27
|
+
end
|
16
28
|
end
|
17
29
|
|
18
30
|
context "without Handler" do
|
@@ -61,6 +73,10 @@ describe Rack::Berater::Handler do
|
|
61
73
|
it "should not send a body" do
|
62
74
|
expect(response.body).to be_empty
|
63
75
|
end
|
76
|
+
|
77
|
+
it "should not send the Content-Type header" do
|
78
|
+
expect(response.headers.keys).not_to include(Rack::CONTENT_TYPE)
|
79
|
+
end
|
64
80
|
end
|
65
81
|
|
66
82
|
context "with body nil" do
|
@@ -94,5 +110,17 @@ describe Rack::Berater::Handler do
|
|
94
110
|
response
|
95
111
|
end
|
96
112
|
end
|
113
|
+
|
114
|
+
context "with custom headers" do
|
115
|
+
let(:options) { { headers: { Rack::CACHE_CONTROL => "no-cache" } } }
|
116
|
+
|
117
|
+
it "should contain the default headers" do
|
118
|
+
expect(response.headers.keys).to include(Rack::CONTENT_TYPE)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should also contain custom header" do
|
122
|
+
expect(response.headers).to include(options[:headers])
|
123
|
+
end
|
124
|
+
end
|
97
125
|
end
|
98
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-berater
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Pepper
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: berater
|
@@ -108,7 +108,7 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
111
|
+
description: limit incoming requests
|
112
112
|
email:
|
113
113
|
executables: []
|
114
114
|
extensions: []
|