request_headers_middleware 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +2 -1
- data/README.md +16 -0
- data/lib/request_headers_middleware.rb +1 -0
- data/lib/request_headers_middleware/faraday_adapter.rb +13 -0
- data/lib/request_headers_middleware/version.rb +1 -1
- data/request_headers_middleware.gemspec +8 -7
- data/spec/request_headers_middleware/faraday_adapter.rb +40 -0
- metadata +61 -21
- data/Gemfile.lock +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 09a7ee538f2104a6109fcfd70232ef743062878b772069fa78b71071386c35ef
|
4
|
+
data.tar.gz: d72c282ea9fced30d6dbd955af7bc8cd0a99760b4ee98802e802a030d0e28ce5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42cf2204c5c96fb519c86ef0517d93513cb2747b2dec87360ce5e86fdca807e1877d30f0901550df1fdd9eb2d1e7828db39a5904937dc03cbd66661f55d7a0d4
|
7
|
+
data.tar.gz: dbe3ea0a4d2855ced1bc7313a319eac57de0aa27f275b47c4371c0ba99d77b2be1b8b35577e4f39fbbac6e399f2d50f6ef530ebf54118f213be87e50e9d93297
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -76,6 +76,13 @@ Faraday.new(
|
|
76
76
|
)
|
77
77
|
```
|
78
78
|
|
79
|
+
Or you can use middleware:
|
80
|
+
```ruby
|
81
|
+
connection = Faraday.new 'http://example.com/api' do |conn|
|
82
|
+
conn.use RequestHeadersMiddleware::FaradayAdapter
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
79
86
|
### JsonApiClient
|
80
87
|
|
81
88
|
For a class extended from *JsonApiClient* it could work like this. Let's call the class *MyJsonApiClient*.
|
@@ -86,6 +93,15 @@ MyJsonApiClient.with_headers(RequestHeadersMiddleware.store) do
|
|
86
93
|
end
|
87
94
|
```
|
88
95
|
|
96
|
+
Another option is to use it globally for any request by using middleware:
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
connection do |conn|
|
100
|
+
conn.use RequestHeadersMiddleware::FaradayAdapter
|
101
|
+
end
|
102
|
+
|
103
|
+
```
|
104
|
+
|
89
105
|
### Whitelist
|
90
106
|
|
91
107
|
Per default the middleware applies a whitelist to only filter *X-Request-Id* header. Generally this is just as follows:
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday_middleware'
|
4
|
+
|
5
|
+
module RequestHeadersMiddleware
|
6
|
+
class FaradayAdapter < Faraday::Middleware
|
7
|
+
def call(env)
|
8
|
+
env[:request_headers].merge! RequestHeadersMiddleware.store
|
9
|
+
|
10
|
+
@app.call(env)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.email = ['marc.grimme@gmail.com']
|
12
12
|
gem.description = 'RequestHeader gives you per-req global header storage.'
|
13
13
|
gem.summary = 'RequestStore gives you per-reqt global header storage.'
|
14
|
-
gem.homepage = 'http://github.com/
|
14
|
+
gem.homepage = 'http://github.com/fidor/request_headers_middleware'
|
15
15
|
gem.licenses = ['MIT']
|
16
16
|
|
17
17
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
@@ -19,10 +19,11 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
20
20
|
gem.require_paths = ['lib']
|
21
21
|
|
22
|
-
gem.add_dependency '
|
23
|
-
gem.
|
24
|
-
gem.add_development_dependency '
|
25
|
-
gem.add_development_dependency '
|
26
|
-
gem.add_development_dependency '
|
27
|
-
gem.add_development_dependency '
|
22
|
+
gem.add_dependency 'faraday_middleware', '~> 0.9'
|
23
|
+
gem.add_dependency 'request_store', '~> 1.4', '>= 1.4.0'
|
24
|
+
gem.add_development_dependency 'rack', '~> 1.6', '>= 1.6.5'
|
25
|
+
gem.add_development_dependency 'rake', '~> 12.0', '>= 12.0.0'
|
26
|
+
gem.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
|
27
|
+
gem.add_development_dependency 'rubocop', '~> 0.53.0'
|
28
|
+
gem.add_development_dependency 'simplecov', '~> 0.12.0'
|
28
29
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
|
6
|
+
describe RequestHeadersMiddleware::FaradayAdapter do
|
7
|
+
context 'when MockRackApp called with a request' do
|
8
|
+
let(:app) { MockRackApp.new }
|
9
|
+
let(:env) do
|
10
|
+
Rack::MockRequest.env_for('/example')
|
11
|
+
end
|
12
|
+
subject { described_class.new(app) }
|
13
|
+
|
14
|
+
it 'merges current headers with RequestHeadersMiddleware.store' do
|
15
|
+
allow(RequestHeadersMiddleware).to receive(:store).and_return('X-Request-Id': '1234')
|
16
|
+
env[:request_headers] = { 'X-Test': '4321' }
|
17
|
+
|
18
|
+
subject.call(env)
|
19
|
+
expect(env[:request_headers]).to eq('X-Test': '4321', 'X-Request-Id': '1234')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'adapter is used as faraday middleware ' do
|
24
|
+
before do
|
25
|
+
stub_request(:get, /example.com/)
|
26
|
+
|
27
|
+
Faraday.default_connection = Faraday.new do |conn|
|
28
|
+
conn.request :url_encoded
|
29
|
+
conn.use RequestHeadersMiddleware::FaradayAdapter
|
30
|
+
conn.adapter Faraday.default_adapter
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'merges current headers with RequestHeadersMiddleware.store' do
|
35
|
+
expect_any_instance_of(RequestHeadersMiddleware::FaradayAdapter).to receive(:call)
|
36
|
+
|
37
|
+
Faraday.get('http://example.com')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,99 +1,137 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_headers_middleware
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marc Grimme
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday_middleware
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.9'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: request_store
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - ">="
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
33
|
+
version: 1.4.0
|
34
|
+
- - "~>"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '1.4'
|
20
37
|
type: :runtime
|
21
38
|
prerelease: false
|
22
39
|
version_requirements: !ruby/object:Gem::Requirement
|
23
40
|
requirements:
|
24
41
|
- - ">="
|
25
42
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
43
|
+
version: 1.4.0
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.4'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: rack
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
30
50
|
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.6'
|
31
54
|
- - ">="
|
32
55
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
56
|
+
version: 1.6.5
|
34
57
|
type: :development
|
35
58
|
prerelease: false
|
36
59
|
version_requirements: !ruby/object:Gem::Requirement
|
37
60
|
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.6'
|
38
64
|
- - ">="
|
39
65
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
66
|
+
version: 1.6.5
|
41
67
|
- !ruby/object:Gem::Dependency
|
42
68
|
name: rake
|
43
69
|
requirement: !ruby/object:Gem::Requirement
|
44
70
|
requirements:
|
45
71
|
- - ">="
|
46
72
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
73
|
+
version: 12.0.0
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '12.0'
|
48
77
|
type: :development
|
49
78
|
prerelease: false
|
50
79
|
version_requirements: !ruby/object:Gem::Requirement
|
51
80
|
requirements:
|
52
81
|
- - ">="
|
53
82
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
83
|
+
version: 12.0.0
|
84
|
+
- - "~>"
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '12.0'
|
55
87
|
- !ruby/object:Gem::Dependency
|
56
88
|
name: rspec
|
57
89
|
requirement: !ruby/object:Gem::Requirement
|
58
90
|
requirements:
|
59
91
|
- - ">="
|
60
92
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
93
|
+
version: 3.5.0
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.5'
|
62
97
|
type: :development
|
63
98
|
prerelease: false
|
64
99
|
version_requirements: !ruby/object:Gem::Requirement
|
65
100
|
requirements:
|
66
101
|
- - ">="
|
67
102
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
103
|
+
version: 3.5.0
|
104
|
+
- - "~>"
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '3.5'
|
69
107
|
- !ruby/object:Gem::Dependency
|
70
108
|
name: rubocop
|
71
109
|
requirement: !ruby/object:Gem::Requirement
|
72
110
|
requirements:
|
73
|
-
- - "
|
111
|
+
- - "~>"
|
74
112
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
113
|
+
version: 0.53.0
|
76
114
|
type: :development
|
77
115
|
prerelease: false
|
78
116
|
version_requirements: !ruby/object:Gem::Requirement
|
79
117
|
requirements:
|
80
|
-
- - "
|
118
|
+
- - "~>"
|
81
119
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
120
|
+
version: 0.53.0
|
83
121
|
- !ruby/object:Gem::Dependency
|
84
122
|
name: simplecov
|
85
123
|
requirement: !ruby/object:Gem::Requirement
|
86
124
|
requirements:
|
87
|
-
- - "
|
125
|
+
- - "~>"
|
88
126
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
127
|
+
version: 0.12.0
|
90
128
|
type: :development
|
91
129
|
prerelease: false
|
92
130
|
version_requirements: !ruby/object:Gem::Requirement
|
93
131
|
requirements:
|
94
|
-
- - "
|
132
|
+
- - "~>"
|
95
133
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
134
|
+
version: 0.12.0
|
97
135
|
description: RequestHeader gives you per-req global header storage.
|
98
136
|
email:
|
99
137
|
- marc.grimme@gmail.com
|
@@ -107,20 +145,21 @@ files:
|
|
107
145
|
- ".ruby-version"
|
108
146
|
- ".travis.yml"
|
109
147
|
- Gemfile
|
110
|
-
- Gemfile.lock
|
111
148
|
- LICENSE.txt
|
112
149
|
- README.md
|
113
150
|
- Rakefile
|
114
151
|
- bin/travis
|
115
152
|
- lib/request_headers_middleware.rb
|
153
|
+
- lib/request_headers_middleware/faraday_adapter.rb
|
116
154
|
- lib/request_headers_middleware/middleware.rb
|
117
155
|
- lib/request_headers_middleware/railtie.rb
|
118
156
|
- lib/request_headers_middleware/version.rb
|
119
157
|
- request_headers_middleware.gemspec
|
158
|
+
- spec/request_headers_middleware/faraday_adapter.rb
|
120
159
|
- spec/request_headers_middleware_spec.rb
|
121
160
|
- spec/spec_helper.rb
|
122
161
|
- spec/support/mock_rack_app.rb
|
123
|
-
homepage: http://github.com/
|
162
|
+
homepage: http://github.com/fidor/request_headers_middleware
|
124
163
|
licenses:
|
125
164
|
- MIT
|
126
165
|
metadata: {}
|
@@ -140,11 +179,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
179
|
version: '0'
|
141
180
|
requirements: []
|
142
181
|
rubyforge_project:
|
143
|
-
rubygems_version: 2.
|
182
|
+
rubygems_version: 2.7.8
|
144
183
|
signing_key:
|
145
184
|
specification_version: 4
|
146
185
|
summary: RequestStore gives you per-reqt global header storage.
|
147
186
|
test_files:
|
187
|
+
- spec/request_headers_middleware/faraday_adapter.rb
|
148
188
|
- spec/request_headers_middleware_spec.rb
|
149
189
|
- spec/spec_helper.rb
|
150
190
|
- spec/support/mock_rack_app.rb
|
data/Gemfile.lock
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
request_headers_middleware (0.0.4)
|
5
|
-
request_store
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
ast (2.4.0)
|
11
|
-
byebug (9.0.6)
|
12
|
-
diff-lcs (1.2.5)
|
13
|
-
docile (1.1.5)
|
14
|
-
json (2.1.0)
|
15
|
-
parallel (1.12.1)
|
16
|
-
parser (2.5.0.2)
|
17
|
-
ast (~> 2.4.0)
|
18
|
-
powerpack (0.1.1)
|
19
|
-
rack (1.6.5)
|
20
|
-
rainbow (3.0.0)
|
21
|
-
rake (12.0.0)
|
22
|
-
request_store (1.4.0)
|
23
|
-
rack (>= 1.4)
|
24
|
-
rspec (3.5.0)
|
25
|
-
rspec-core (~> 3.5.0)
|
26
|
-
rspec-expectations (~> 3.5.0)
|
27
|
-
rspec-mocks (~> 3.5.0)
|
28
|
-
rspec-core (3.5.4)
|
29
|
-
rspec-support (~> 3.5.0)
|
30
|
-
rspec-expectations (3.5.0)
|
31
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
-
rspec-support (~> 3.5.0)
|
33
|
-
rspec-mocks (3.5.0)
|
34
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
-
rspec-support (~> 3.5.0)
|
36
|
-
rspec-support (3.5.0)
|
37
|
-
rubocop (0.53.0)
|
38
|
-
parallel (~> 1.10)
|
39
|
-
parser (>= 2.5)
|
40
|
-
powerpack (~> 0.1)
|
41
|
-
rainbow (>= 2.2.2, < 4.0)
|
42
|
-
ruby-progressbar (~> 1.7)
|
43
|
-
unicode-display_width (~> 1.0, >= 1.0.1)
|
44
|
-
ruby-progressbar (1.9.0)
|
45
|
-
simplecov (0.12.0)
|
46
|
-
docile (~> 1.1.0)
|
47
|
-
json (>= 1.8, < 3)
|
48
|
-
simplecov-html (~> 0.10.0)
|
49
|
-
simplecov-html (0.10.0)
|
50
|
-
unicode-display_width (1.3.0)
|
51
|
-
|
52
|
-
PLATFORMS
|
53
|
-
ruby
|
54
|
-
|
55
|
-
DEPENDENCIES
|
56
|
-
byebug
|
57
|
-
rack
|
58
|
-
rake
|
59
|
-
request_headers_middleware!
|
60
|
-
rspec
|
61
|
-
rubocop
|
62
|
-
simplecov
|
63
|
-
|
64
|
-
BUNDLED WITH
|
65
|
-
1.16.1
|