mn_middleware_gem 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6609128eb17a1b95d8ea9972f2267e3ce443ef7a4a8b7c9f2ecff8597b55d071
4
- data.tar.gz: def274482bf188098ed5a22b18fae4b18359b572d44a39c1d6cd6a1ecfc1d2da
3
+ metadata.gz: 0dcc70086267dde8dd81032660c7722a9a43dc1ea585ba7f8cab8c760691eaea
4
+ data.tar.gz: 7e848ae5a0e189cbed0285eaac80252dddce0b56bcecdb144c668e8ad9bd1768
5
5
  SHA512:
6
- metadata.gz: 372cfd18068c85f1a8630fe1cf824b9692822afa115626a8753ccbe5d91150b2e0f0934547fdc0d181cbee114790e32f47b094d7ba843d282cb20a939139355a
7
- data.tar.gz: ddc969067be15fd56268caa51e7a50547dc8e301a3e11966dc695e4cde5c2988aada9872f3b1a7c946c1c56f07c531b794e1700b388e8785fd5d4ee6a5367ace
6
+ metadata.gz: e656029783ef8e62180d7bf08d240ed5f0db42eccf982f1ef262cc55598d2ccafc05aad0446d9d8796a9d7b77e85ca14d74abd8c0ab97c078580a3ae1e11d747
7
+ data.tar.gz: 1fd1d5f8bf712c45ce18df4b536691c4d1c1243fe357f80889202ee2d7da95966e995906b2993f74f087df22de5e45b32fb29cdd632497791333f3ac9442a9e1
@@ -1,42 +1,44 @@
1
1
  require 'securerandom'
2
2
  require 'net/http'
3
3
 
4
- class MnMiddleware::CorrelationId
5
- def initialize app
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- request_id = nil
11
-
12
- # see if you can get an existing request id
13
- # from these sources, in order of priority
14
- if env['HTTP_X_REQUEST_ID']
15
- request_id = env['HTTP_X_REQUEST_ID']
16
- Rails.logger.debug "Found HTTP_X_REQUEST_ID #{request_id}"
17
- elsif env['HTTP_X_AMZN_TRACE_ID']
18
- request_id = env['HTTP_X_REQUEST_ID'] = env['HTTP_X_AMZN_TRACE_ID'].match(/^.*Root=([^;]*).*$/).captures[0]
19
- Rails.logger.debug "Found HTTP_X_AMZN_TRACE_ID #{request_id}"
4
+ module MnMiddleware
5
+ class CorrelationId
6
+ def initialize app
7
+ @app = app
20
8
  end
21
9
 
22
- # if no request id is available, generate one
23
- if request_id.nil?
24
- request_id = env['HTTP_X_REQUEST_ID'] = SecureRandom.uuid
25
- Rails.logger.debug "Set request_id #{request_id}"
10
+ def call(env)
11
+ request_id = nil
12
+
13
+ # see if you can get an existing request id
14
+ # from these sources, in order of priority
15
+ if env['HTTP_X_REQUEST_ID']
16
+ request_id = env['HTTP_X_REQUEST_ID']
17
+ Rails.logger.debug "Found HTTP_X_REQUEST_ID #{request_id}"
18
+ elsif env['HTTP_X_AMZN_TRACE_ID']
19
+ request_id = env['HTTP_X_REQUEST_ID'] = env['HTTP_X_AMZN_TRACE_ID'].match(/^.*Root=([^;]*).*$/).captures[0]
20
+ Rails.logger.debug "Found HTTP_X_AMZN_TRACE_ID #{request_id}"
21
+ end
22
+
23
+ # if no request id is available, generate one
24
+ if request_id.nil?
25
+ request_id = env['HTTP_X_REQUEST_ID'] = SecureRandom.uuid
26
+ Rails.logger.debug "Set request_id #{request_id}"
27
+ end
28
+
29
+ # set the request id in the request store
30
+ # so we can use it later in the Net::HTTPHeader monkey patch
31
+ RequestStore.store[:request_id] = request_id
32
+
33
+ # call the superclass and get the app return values
34
+ status, headers, response = @app.call(env)
35
+
36
+ # set the request id in the response header
37
+ headers['X-Request-Id'] = request_id
38
+
39
+ # return all the values back up
40
+ [status, headers, response]
26
41
  end
27
-
28
- # set the request id in the request store
29
- # so we can use it later in the Net::HTTPHeader monkey patch
30
- RequestStore.store[:request_id] = request_id
31
-
32
- # call the superclass and get the app return values
33
- status, headers, response = @app.call(env)
34
-
35
- # set the request id in the response header
36
- headers['X-Request-Id'] = request_id
37
-
38
- # return all the values back up
39
- [status, headers, response]
40
42
  end
41
43
  end
42
44
 
@@ -1,15 +1,17 @@
1
- class MnMiddleware::RemoteIpLogger
2
- def initialize(app)
3
- @app = app
4
- end
1
+ module MnMiddleware
2
+ class RemoteIpLogger
3
+ def initialize(app)
4
+ @app = app
5
+ end
5
6
 
6
- def call(env)
7
- if env["HTTP_X_FORWARDED_FOR"]
8
- remote_ip = env["HTTP_X_FORWARDED_FOR"].split(",")[0]
9
- env['REMOTE_ADDR'] = env["action_dispatch.remote_ip"] = env["HTTP_X_FORWARDED_FOR"] = remote_ip
10
- @app.call(env)
11
- else
12
- @app.call(env)
7
+ def call(env)
8
+ if env["HTTP_X_FORWARDED_FOR"]
9
+ remote_ip = env["HTTP_X_FORWARDED_FOR"].split(",")[0]
10
+ env['REMOTE_ADDR'] = env["action_dispatch.remote_ip"] = env["HTTP_X_FORWARDED_FOR"] = remote_ip
11
+ @app.call(env)
12
+ else
13
+ @app.call(env)
14
+ end
13
15
  end
14
16
  end
15
17
  end
@@ -1,3 +1,3 @@
1
1
  module MnMiddlewareGem
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mn_middleware_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shamim Mirzai