request_id 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -15,15 +15,18 @@ module Rack
15
15
  # logger.info "request_id=#{Thread.current[:request_id]} Hello world"
16
16
  # # => request_id=a08a6712229fb991c0e5026c246862c7 Hello world
17
17
  class RequestId
18
- REQUEST_ID_HEADER = 'HTTP_HEROKU_REQUEST_ID'.freeze
18
+ REQUEST_HEADER = 'HTTP_HEROKU_REQUEST_ID'.freeze
19
+ RESPONSE_HEADER = 'X-Request-Id'.freeze
19
20
 
20
21
  def initialize(app, options = {})
21
22
  @app = app
22
23
  end
23
24
 
24
25
  def call(env)
25
- ::RequestId.request_id = env[REQUEST_ID_HEADER]
26
- @app.call(env)
26
+ ::RequestId.request_id = env[REQUEST_HEADER]
27
+ status, headers, body = @app.call(env)
28
+ headers[RESPONSE_HEADER] ||= ::RequestId.request_id
29
+ [status, headers, body]
27
30
  ensure
28
31
  ::RequestId.request_id = nil
29
32
  end
@@ -1,3 +1,3 @@
1
1
  module RequestId
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'securerandom'
3
3
 
4
4
  describe Rack::RequestId do
5
- let(:app) { double('app', call: nil) }
5
+ let(:app) { double('app', call: [200, {}, ['Body']]) }
6
6
  let(:middleware) { described_class.new app }
7
7
 
8
8
  describe '.call' do
@@ -15,6 +15,11 @@ describe Rack::RequestId do
15
15
  middleware.call('HTTP_HEROKU_REQUEST_ID' => request_id)
16
16
  end
17
17
 
18
+ it 'sets the X-Request-Id header in the response' do
19
+ status, headers, body = middleware.call('HTTP_HEROKU_REQUEST_ID' => request_id)
20
+ expect(headers['X-Request-Id']).to eq request_id
21
+ end
22
+
18
23
  context 'when an exception is raised' do
19
24
  it 'still sets the request_id back to nil' do
20
25
  Thread.current.should_receive(:[]=).with(:request_id, request_id)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: request_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  version: '0'
100
100
  segments:
101
101
  - 0
102
- hash: 4065047775900537477
102
+ hash: -2341764705210223496
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  none: false
105
105
  requirements:
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  segments:
110
110
  - 0
111
- hash: 4065047775900537477
111
+ hash: -2341764705210223496
112
112
  requirements: []
113
113
  rubyforge_project:
114
114
  rubygems_version: 1.8.23