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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f314e7cc1779f326294cede2142167c325fd5182cc403b17dcdf2ffa4a0ab2f0
4
- data.tar.gz: c29c7bc00999c22d65ed1da8268761ff1633f936e58e856dd9f2b3dad189ce80
3
+ metadata.gz: 9d5d8146dab264d6d7e2f1177101b9f7f5c62f44840964fb9672b7de7d01fe20
4
+ data.tar.gz: '058153f00f46e7eac0d26eb7039af4624e9636954fd59999f9bcf419fe559abf'
5
5
  SHA512:
6
- metadata.gz: da2a45e51025660adc160604297d3614fea894b79b203be1ee8b337832281d59d4a4f8e3e4aa222209754251763cecced1e225a039921e9f8a979a2b741410e6
7
- data.tar.gz: fc581d18446b2fbab925e49a4cb984d06d7112f1e90bde8dffb07ae124d0a061a9f6c107afd4addc1c8058ec5be503316d5a7437042b9d9c3ffbf602c6522af4
6
+ metadata.gz: 04204eb3b4029928a706b5d9894984462698ee337ccdb3d96e224da1bfc8debf4970b1eb5ba0b8b8cd14960171b8e926d5369f12eea66fcd42ded4bad5de1738
7
+ data.tar.gz: a3db075dddeff6e111cdac3bdef7236e8d461fb86c9aa7b696dd15ffd2b8cb5db2b755c07f2465e51eeee5963461a5ae72985aa924e4d9a1340a18987f428391
@@ -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
 
@@ -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.4.0"
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"
@@ -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 'requst.coach' with
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
- next unless key =~ /^HTTP_/
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.downcase, self.class.apply_header_rule(key.downcase, value)]
71
+ [key, self.class.apply_header_rule(key, value)] if key
63
72
  end.compact
64
73
 
65
74
  Hash[header_value_pairs]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coach
4
- VERSION = "2.0.0"
4
+ VERSION = "2.1.0"
5
5
  end
@@ -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
- "foo" => "bar",
52
- "HTTP_foo" => "bar",
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
- it "filters headers allowing only those prefixed with 'HTTP_'" do
66
- allow(mock_request).to receive(:fullpath).and_return(nil)
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
- expect(serialized[:headers]).to_not include("foo")
69
- expect(serialized[:headers]).to include("http_foo")
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.0.0
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-06-14 00:00:00.000000000 Z
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.4.0
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.4.0
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
- rubygems_version: 3.0.2
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