heroku-request-id 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -34,6 +34,14 @@ requests by adding this to an initializer.
34
34
  HerokuRequestId::Middleware.html_comment = true
35
35
  ```
36
36
 
37
+ You can also configure the gem to copy the `HTTP_HEROKU_REQUEST_ID`
38
+ header, which is set by heroku, into the `HTTP_X_REQUEST_ID` header,
39
+ which is used by `ActionDispatch:: RequestId`.
40
+
41
+ ```ruby
42
+ HerokuRequestId::Middleware.x_request_id_replication = true
43
+ ```
44
+
37
45
  ## Contributing
38
46
 
39
47
  1. Fork it
@@ -2,7 +2,7 @@ module HerokuRequestId
2
2
  class Middleware
3
3
 
4
4
  def initialize(app)
5
- @app = app
5
+ @app = app
6
6
  end
7
7
 
8
8
  @@html_comment = false
@@ -11,8 +11,8 @@ module HerokuRequestId
11
11
  @@html_comment
12
12
  end
13
13
 
14
- def self.html_comment= hc
15
- @@html_comment = hc
14
+ def self.html_comment= value
15
+ @@html_comment = value
16
16
  end
17
17
 
18
18
  @@log_line = true
@@ -21,13 +21,24 @@ module HerokuRequestId
21
21
  @@log_line
22
22
  end
23
23
 
24
- def self.log_line= hc
25
- @@log_line = hc
24
+ def self.log_line= value
25
+ @@log_line = value
26
+ end
27
+
28
+ @@x_request_id_replication = false
29
+
30
+ def self.x_request_id_replication
31
+ @@x_request_id_replication
32
+ end
33
+
34
+ def self.x_request_id_replication= value
35
+ @@x_request_id_replication = value
26
36
  end
27
37
 
28
38
  def call(env)
29
39
  @start = Time.now
30
40
  @request_id = env['HTTP_HEROKU_REQUEST_ID']
41
+ env["HTTP_X_REQUEST_ID"] = @request_id if self.class.x_request_id_replication
31
42
  @status, @headers, @response = @app.call(env)
32
43
  [@status, @headers, self]
33
44
  end
@@ -1,7 +1,7 @@
1
1
  module HerokuRequestId
2
2
  class Railtie < Rails::Railtie
3
3
  initializer 'heroku_request_id.add_middleware' do |app|
4
- app.config.middleware.insert_after 'Rack::Lock', "HerokuRequestId::Middleware"
4
+ app.config.middleware.insert 0, "HerokuRequestId::Middleware"
5
5
  end
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module HerokuRequestId
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -5,40 +5,75 @@ describe HerokuRequestId::Middleware do
5
5
  include Rack::Test::Methods
6
6
 
7
7
  let(:inner_app) do
8
- lambda { |env| [200, {'Content-Type' => 'text/html'}, ['<body>All good!</body>']] }
8
+ lambda { |env| [200, {'Content-Type' => 'text/html'}, ['<body>All good!</body>']] }
9
9
  end
10
10
 
11
11
  let(:app) { HerokuRequestId::Middleware.new(inner_app) }
12
12
 
13
+ subject do
14
+ capture_stdout { get("/", {}, { "HTTP_HEROKU_REQUEST_ID" => "the_id_string" }) }
15
+ end
16
+
13
17
  it "prints the request id to stdout by default" do
14
- output = capture_stdout { get "/" }
18
+ output = subject
15
19
  output.should match("heroku-request-id")
20
+ output.should match("the_id_string")
16
21
  end
17
22
 
18
23
  it "does not print the request id to stdout if log_line == false" do
19
24
  HerokuRequestId::Middleware.log_line = false
20
- output = capture_stdout { get "/" }
25
+ output = subject
21
26
  output.should_not match("heroku-request-id")
27
+ output.should_not match("the_id_string")
22
28
  # reset html_comment so that random test order works
23
29
  HerokuRequestId::Middleware.log_line = true
24
30
  end
25
31
 
26
32
  it "does not add a comment with the Heroku request id by default" do
27
- capture_stdout { get "/" }
33
+ subject
28
34
  last_response.body.should_not match("Heroku request id")
35
+ last_response.body.should_not match("the_id_string")
29
36
  end
30
37
 
31
38
  it "does add a comment with the Heroku request id if html_comment == true" do
32
39
  HerokuRequestId::Middleware.html_comment = true
33
- capture_stdout { get "/" }
40
+ subject
34
41
  last_response.body.should match("Heroku request id")
42
+ last_response.body.should match("the_id_string")
35
43
  # reset html_comment so that random test order works
36
44
  HerokuRequestId::Middleware.html_comment = false
37
45
  end
38
46
 
39
47
  it "makes no change to response status" do
40
- capture_stdout { get "/" }
48
+ subject
41
49
  last_response.should be_ok
42
50
  end
43
51
 
52
+
53
+ # my silly but effective way to test if the header gets replicated/passed forward.
54
+ # i searched and couldn't figure out the typical way of testing
55
+ # if a header is passed down the stack, perhaps someone who knows can replace this.
56
+ describe "header replication into x-request-id" do
57
+ let(:inner_app) do
58
+ lambda { |env|
59
+ [200, {'Content-Type' => 'text/html'}, [env["HTTP_X_REQUEST_ID"]]]
60
+ }
61
+ end
62
+ let(:app){ HerokuRequestId::Middleware.new(inner_app) }
63
+ context "by default" do
64
+ it "does not replicate the heroku header into rails header" do
65
+ subject
66
+ last_response.body.should eq ""
67
+ end
68
+ end
69
+ context "when x_request_id_replication == true" do
70
+ before{HerokuRequestId::Middleware.x_request_id_replication = true}
71
+ after{HerokuRequestId::Middleware.x_request_id_replication = false}
72
+ it "replicates the heroku header into rails header" do
73
+ subject
74
+ last_response.body.should eq "the_id_string"
75
+ end
76
+ end
77
+ end
78
+
44
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku-request-id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-22 00:00:00.000000000 Z
12
+ date: 2013-05-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  segments:
114
114
  - 0
115
- hash: 3422138691376202609
115
+ hash: 2380672724000137210
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
@@ -121,10 +121,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  segments:
123
123
  - 0
124
- hash: 3422138691376202609
124
+ hash: 2380672724000137210
125
125
  requirements: []
126
126
  rubyforge_project:
127
- rubygems_version: 1.8.24
127
+ rubygems_version: 1.8.25
128
128
  signing_key:
129
129
  specification_version: 3
130
130
  summary: Simple Rack middleware to log the heroku request id and write it to the end