request_id 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: 04f6bb692a9428eae84c65802ef209c801b5f621
4
- data.tar.gz: d9d99f2739d1f495b2872ff54c3b48171ba4941b
3
+ metadata.gz: 32098034b450d59355544d24586315a661db4476
4
+ data.tar.gz: be4cf3f3dbd644c9a35d9acd55961fff6eabbf23
5
5
  SHA512:
6
- metadata.gz: 8a387cc775203c7f9a3726c430059e39d0bad5b2a68356db35200211f314d0b23b537f503a61fb55debb355294daf4ebd0f577b753fdff24b33f3c6bc664de96
7
- data.tar.gz: 7a8ca15f5175521d60a9c42d6d4cede5cde21d26265b67df1234a65d5bba226de805001e23f900d739af7bdbb6736dd55c09a3d080eb2cb3a4fa73a0d9bd1dbe
6
+ metadata.gz: 066273aa2c77438d5c12be5f4b5be07f5ae194e4fe6d1a8df3b2c99256e4f80e5f4f182a6bed87093aa9ed2ed8802d236ad13f48e97e5182f663feda22afe736
7
+ data.tar.gz: 1f66869a4275451097a7742b4a9a18c4566670e51293451b867b3562c07a773cd68fa51118d51b5f9cb8576efc78acb2e4d2a62e25f9704308abe0d0f6a0e8ce
@@ -0,0 +1,27 @@
1
+ require 'request_id'
2
+ require 'faraday'
3
+
4
+ module Faraday
5
+ class RequestId < Faraday::Middleware
6
+ HEADER = 'X-Request-Id'.freeze
7
+
8
+ def call(env)
9
+ set_header(env) if needs_header?(env)
10
+ @app.call(env)
11
+ end
12
+
13
+ private
14
+
15
+ def needs_header?(env)
16
+ request_id && !env[:request_headers][HEADER]
17
+ end
18
+
19
+ def set_header(env)
20
+ env[:request_headers][HEADER] = request_id
21
+ end
22
+
23
+ def request_id
24
+ ::RequestId.request_id
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module RequestId
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.3'
22
22
  spec.add_development_dependency 'rake'
23
23
  spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'faraday'
24
25
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+ require 'faraday/request_id'
3
+
4
+ describe Faraday::RequestId do
5
+ let(:app) { double('app', call: nil) }
6
+ let(:middleware) { described_class.new(app) }
7
+
8
+ describe '.call' do
9
+ context 'when a request_id is set' do
10
+ before do
11
+ RequestId.stub(request_id: SecureRandom.hex)
12
+ end
13
+
14
+ it 'adds the X-Request-Id header' do
15
+ env = { request_headers: {} }
16
+ middleware.call(env)
17
+ expect(env[:request_headers]['X-Request-Id']).to eq RequestId.request_id
18
+ end
19
+ end
20
+
21
+ context 'when no request_id is set' do
22
+ before do
23
+ RequestId.stub(request_id: nil)
24
+ end
25
+
26
+ it 'does not add the X-Request-Id header' do
27
+ env = { request_headers: {} }
28
+ middleware.call(env)
29
+ expect(env[:request_headers]).to_not have_key 'X-Request-Id'
30
+ end
31
+ end
32
+
33
+ context 'when a request_id is already set in request headers' do
34
+ let(:request_id) { SecureRandom.hex }
35
+
36
+ it 'uses the request id from the env hash' do
37
+ env = { request_headers: { 'X-Request-Id' => request_id } }
38
+ middleware.call(env)
39
+ expect(env[:request_headers]['X-Request-Id']).to eq request_id
40
+ end
41
+ end
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric J. Holmes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-04 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  description: Classes for tracking request id
56
70
  email:
57
71
  - eric@ejholmes.net
@@ -66,6 +80,7 @@ files:
66
80
  - LICENSE.txt
67
81
  - README.md
68
82
  - Rakefile
83
+ - lib/faraday/request_id.rb
69
84
  - lib/rack/request_id.rb
70
85
  - lib/request_id.rb
71
86
  - lib/request_id/configuration.rb
@@ -74,6 +89,7 @@ files:
74
89
  - lib/sidekiq/middleware/client/request_id.rb
75
90
  - lib/sidekiq/middleware/server/request_id.rb
76
91
  - request_id.gemspec
92
+ - spec/faraday/request_id_spec.rb
77
93
  - spec/rack/request_id_spec.rb
78
94
  - spec/request_id_spec.rb
79
95
  - spec/sidekiq/middleware/client/request_id_spec.rb
@@ -105,6 +121,7 @@ signing_key:
105
121
  specification_version: 4
106
122
  summary: Classes for tracking request id
107
123
  test_files:
124
+ - spec/faraday/request_id_spec.rb
108
125
  - spec/rack/request_id_spec.rb
109
126
  - spec/request_id_spec.rb
110
127
  - spec/sidekiq/middleware/client/request_id_spec.rb