rack-berater 0.0.1 → 0.0.2

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
  SHA256:
3
- metadata.gz: a1fad5e57124897f72b0fac11bf460c6b3dc279d057f56f22127ec32274d782d
4
- data.tar.gz: aa7e1c738a450ff6fb72aa9b92e1211ed51c544f801a2ffef475a2a89805db5c
3
+ metadata.gz: 2a5812fba3c2523be30274bcc192d67ba7cebbb1d2b52dcc0ca403d69c39630c
4
+ data.tar.gz: 46152472d4af26a86e506a9150ff9c56743490707b630ecddc94beb0e63f7448
5
5
  SHA512:
6
- metadata.gz: 0ec05fa53c35aea22a9c29e93b5d509c8a161364542641ada1af1c421320d671cd634dc8ab74abc597f38a056fb3d8638b69786cf82e26357b0ace12bf483ee9
7
- data.tar.gz: c9f1c61d05ac9f297b88fad401fdf635cd553a15d2040a2fc7e45282fe2776e00967b8e7181cec5a621c5cb69771676cf7d70a34ee63e6be2b74dd7784b7b7d2
6
+ metadata.gz: '079407a6fd8d63c849809c972ef15739de09bd490c1e3a4046ae047dbba8b36cb7e5f0606c17b5e5a6a74ce8ec9fa95f61139afc3937a5c30643fe85ff59e91d'
7
+ data.tar.gz: 7d6ede65719ed13181c25aca35a48c941ee9c4777caa4f56eede0552b4acdc39d2989069659217327a0b3bc494d0c178b1ee1faa21e42f5c70dd4067f4fb077e
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Berater
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
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 { expect(response.status).to eq 200 }
15
- it { expect(response.body).to eq "OK" }
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.1
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-12 00:00:00.000000000 Z
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: []