coach 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +12 -1
- data/coach.gemspec +1 -1
- data/lib/coach/notifications.rb +1 -1
- data/lib/coach/request_serializer.rb +11 -2
- data/lib/coach/version.rb +1 -1
- data/spec/lib/coach/request_serializer_spec.rb +32 -8
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d5d8146dab264d6d7e2f1177101b9f7f5c62f44840964fb9672b7de7d01fe20
|
4
|
+
data.tar.gz: '058153f00f46e7eac0d26eb7039af4624e9636954fd59999f9bcf419fe559abf'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04204eb3b4029928a706b5d9894984462698ee337ccdb3d96e224da1bfc8debf4970b1eb5ba0b8b8cd14960171b8e926d5369f12eea66fcd42ded4bad5de1738
|
7
|
+
data.tar.gz: a3db075dddeff6e111cdac3bdef7236e8d461fb86c9aa7b696dd15ffd2b8cb5db2b755c07f2465e51eeee5963461a5ae72985aa924e4d9a1340a18987f428391
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,13 @@
|
|
4
4
|
|
5
5
|
No unreleased changes.
|
6
6
|
|
7
|
+
# 2.1.0 / 2019-11-14
|
8
|
+
|
9
|
+
* [#79](https://github.com/gocardless/coach/pull/79) RequestSerializer will now
|
10
|
+
return the 'http_content_type' and 'http_content_length' filtered headers.
|
11
|
+
|
12
|
+
* [#75](https://github.com/gocardless/coach/pull/75) Documentation update.
|
13
|
+
|
7
14
|
# 2.0.0 / 2019-06-13
|
8
15
|
|
9
16
|
## Breaking changes
|
data/README.md
CHANGED
@@ -309,10 +309,21 @@ solution to Rails `process_action.action_controller` event emitted on controller
|
|
309
309
|
The benchmarking data includes information on how long each middleware took to process,
|
310
310
|
along with the total duration of the chain.
|
311
311
|
|
312
|
+
For coach to emit `request.coach` events, it first needs to be subscribed to handler/middleware events:
|
313
|
+
|
314
|
+
```ruby
|
315
|
+
Coach::Notifications.subscribe!
|
316
|
+
|
317
|
+
# Now you can subscribe to and use request.coach events, e.g.
|
318
|
+
ActiveSupport::Notifications.subscribe("request.coach") do |_, event|
|
319
|
+
Rails.logger.info(event)
|
320
|
+
end
|
321
|
+
```
|
322
|
+
|
312
323
|
You can add additional metadata to the notifications published by Coach by calling the
|
313
324
|
`log_metadata` method from inside your Coach middlewares.
|
314
325
|
|
315
|
-
```
|
326
|
+
```ruby
|
316
327
|
class Tracking < Coach::Middleware
|
317
328
|
requires :user
|
318
329
|
|
data/coach.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency "actionpack", ">= 4.2"
|
22
22
|
spec.add_dependency "activesupport", ">= 4.2"
|
23
23
|
|
24
|
-
spec.add_development_dependency "gc_ruboconfig", "= 2.
|
24
|
+
spec.add_development_dependency "gc_ruboconfig", "= 2.6.1"
|
25
25
|
spec.add_development_dependency "pry", "~> 0.10"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3.2"
|
27
27
|
spec.add_development_dependency "rspec-its", "~> 1.2"
|
data/lib/coach/notifications.rb
CHANGED
@@ -10,7 +10,7 @@ module Coach
|
|
10
10
|
# Notifications is used to coordinate the listening and aggregation of these middleware
|
11
11
|
# notifications, while RequestEvent processes the published data.
|
12
12
|
#
|
13
|
-
# Once a request has completed, Notifications will emit a '
|
13
|
+
# Once a request has completed, Notifications will emit a 'request.coach' event with
|
14
14
|
# aggregated request data.
|
15
15
|
class Notifications
|
16
16
|
# Begin processing/emitting 'request.coach's
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Coach
|
4
4
|
class RequestSerializer
|
5
|
+
# Rack specs dictate that CONTENT_TYPE and CONTENT_LENGTH
|
6
|
+
# are not prefixed with HTTP_.
|
7
|
+
# See https://rubydoc.info/github/rack/rack/master/file/SPEC
|
8
|
+
RACK_UNPREFIXED_HEADERS = %w[CONTENT_TYPE CONTENT_LENGTH].freeze
|
9
|
+
|
5
10
|
def self.header_rules
|
6
11
|
@header_rules ||= {}
|
7
12
|
end
|
@@ -57,9 +62,13 @@ module Coach
|
|
57
62
|
|
58
63
|
def filtered_headers
|
59
64
|
header_value_pairs = @request.filtered_env.map do |key, value|
|
60
|
-
|
65
|
+
key = if RACK_UNPREFIXED_HEADERS.include?(key)
|
66
|
+
"http_#{key.downcase}"
|
67
|
+
elsif key =~ /^HTTP_/
|
68
|
+
key.downcase
|
69
|
+
end
|
61
70
|
|
62
|
-
[key
|
71
|
+
[key, self.class.apply_header_rule(key, value)] if key
|
63
72
|
end.compact
|
64
73
|
|
65
74
|
Hash[header_value_pairs]
|
data/lib/coach/version.rb
CHANGED
@@ -47,10 +47,14 @@ describe Coach::RequestSerializer do
|
|
47
47
|
uuid: nil,
|
48
48
|
method: nil,
|
49
49
|
filtered_parameters: nil,
|
50
|
-
filtered_env:
|
51
|
-
|
52
|
-
|
53
|
-
|
50
|
+
filtered_env: filtered_env)
|
51
|
+
end
|
52
|
+
|
53
|
+
let(:filtered_env) do
|
54
|
+
{
|
55
|
+
"foo" => "bar",
|
56
|
+
"HTTP_foo" => "bar",
|
57
|
+
}
|
54
58
|
end
|
55
59
|
|
56
60
|
describe "#serialize" do
|
@@ -62,11 +66,31 @@ describe Coach::RequestSerializer do
|
|
62
66
|
expect(serialized[:path]).to eq("unknown")
|
63
67
|
end
|
64
68
|
|
65
|
-
|
66
|
-
|
69
|
+
context "filters headers" do
|
70
|
+
before do
|
71
|
+
allow(mock_request).to receive(:fullpath).and_return(nil)
|
72
|
+
end
|
73
|
+
|
74
|
+
it "allowing those prefixed with 'HTTP_'" do
|
75
|
+
expect(serialized[:headers]).to_not include("foo")
|
76
|
+
expect(serialized[:headers]).to include("http_foo")
|
77
|
+
end
|
78
|
+
|
79
|
+
context "Content-Type and Content-Length" do
|
80
|
+
let(:filtered_env) do
|
81
|
+
{
|
82
|
+
"foo" => "foo",
|
83
|
+
"CONTENT_TYPE" => "application/json",
|
84
|
+
"CONTENT_LENGTH" => 42,
|
85
|
+
}
|
86
|
+
end
|
67
87
|
|
68
|
-
|
69
|
-
|
88
|
+
it "prefixing with 'http_'" do
|
89
|
+
expect(serialized[:headers]).to_not include("foo")
|
90
|
+
expect(serialized[:headers]).to include("http_content_type")
|
91
|
+
expect(serialized[:headers]).to include("http_content_length")
|
92
|
+
end
|
93
|
+
end
|
70
94
|
end
|
71
95
|
end
|
72
96
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coach
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GoCardless
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 2.
|
47
|
+
version: 2.6.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 2.
|
54
|
+
version: 2.6.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +165,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
|
-
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 2.7.6
|
169
170
|
signing_key:
|
170
171
|
specification_version: 4
|
171
172
|
summary: Alternative controllers built with middleware
|