request_id 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/rack/request_id.rb +6 -1
- data/lib/request_id/version.rb +1 -1
- data/spec/rack/request_id_spec.rb +30 -0
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9a76b5cd12acc661e7512907335ed0ad7319b950
|
4
|
+
data.tar.gz: f3358b4b485b347c149b01d395ba52df3e9f426d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bda55ec9eb12d58a4742b1c0babb9dbbd4c2c8f6f9418140bb3f01b28ced1287a91656ebb3110c00c8432f958c91b10ce9f76acde17ecf4d63dea32647287aae
|
7
|
+
data.tar.gz: 41cb3c90e7a96031ed8a7b4ff8b38915af99c2a1cc60f20a16202b36be6b432b794a5cd90aa89dde8489c3b0354ddb23705151317d282d53a878f6065d1779ce
|
data/lib/rack/request_id.rb
CHANGED
@@ -26,7 +26,7 @@ module Rack
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def call(env)
|
29
|
-
::RequestId.with(@options[:key], @options[:value].call(env)) do
|
29
|
+
::RequestId.with(@options[:key], @options[:value].call(env) || generate) do
|
30
30
|
status, headers, body = @app.call(env)
|
31
31
|
|
32
32
|
if @options[:response_header]
|
@@ -42,5 +42,10 @@ module Rack
|
|
42
42
|
def default_options
|
43
43
|
{ key: :request_id, value: lambda { |env| env[REQUEST_HEADER] }, response_header: RESPONSE_HEADER }
|
44
44
|
end
|
45
|
+
|
46
|
+
def generate
|
47
|
+
SecureRandom.uuid if ::RequestId.configuration.generate
|
48
|
+
end
|
49
|
+
|
45
50
|
end
|
46
51
|
end
|
data/lib/request_id/version.rb
CHANGED
@@ -21,6 +21,36 @@ describe Rack::RequestId do
|
|
21
21
|
expect(headers['X-Request-Id']).to eq request_id
|
22
22
|
end
|
23
23
|
|
24
|
+
context 'when config.generate == false' do
|
25
|
+
before do
|
26
|
+
RequestId.configure { |c| c.generate = false }
|
27
|
+
end
|
28
|
+
|
29
|
+
after do
|
30
|
+
RequestId.configure { |c| c.generate = true }
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'does not generate a request id if none is present' do
|
34
|
+
status, headers, body = middleware.call({})
|
35
|
+
expect(headers['X-Request-Id']).to be_empty
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when config.generate == true' do
|
40
|
+
before do
|
41
|
+
RequestId.configure { |c| c.generate = true }
|
42
|
+
end
|
43
|
+
|
44
|
+
after do
|
45
|
+
RequestId.configure { |c| c.generate = false }
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'generates a request id if none is present' do
|
49
|
+
status, headers, body = middleware.call({})
|
50
|
+
expect(headers['X-Request-Id']).to_not be_empty
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
24
54
|
context 'when an exception is raised' do
|
25
55
|
it 'still sets the request_id back to nil' do
|
26
56
|
Thread.current.should_receive(:[]=).with(:request_id, request_id)
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: request_id
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
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:
|
11
|
+
date: 2015-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
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
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: faraday
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Classes for tracking request id
|
@@ -73,9 +73,9 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
77
|
-
- .rspec
|
78
|
-
- .travis.yml
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
79
|
- Gemfile
|
80
80
|
- LICENSE
|
81
81
|
- LICENSE.txt
|
@@ -107,17 +107,17 @@ require_paths:
|
|
107
107
|
- lib
|
108
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
|
-
- -
|
110
|
+
- - ">="
|
111
111
|
- !ruby/object:Gem::Version
|
112
112
|
version: '0'
|
113
113
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
requirements: []
|
119
119
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
120
|
+
rubygems_version: 2.4.5
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Classes for tracking request id
|