aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2015-05-23 11:38:07 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2015-05-23 11:38:23 -0700
commitcf985d1a4e7da2ba52f968aceee650bbdda6287e (patch)
tree40bc3a2226f56ae75961c6646c86770171e8cf68 /actionpack
parent989296ff09ed879453897e0f223608cc0b60ad9f (diff)
downloadrails-cf985d1a4e7da2ba52f968aceee650bbdda6287e.tar.gz
rails-cf985d1a4e7da2ba52f968aceee650bbdda6287e.tar.bz2
rails-cf985d1a4e7da2ba52f968aceee650bbdda6287e.zip
add a branch to eliminate multiple nil checks
if we add an else conditional to the `presence` check, we can eliminate the second `||` branch in the caller
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/middleware/request_id.rb8
1 files changed, 5 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/request_id.rb b/actionpack/lib/action_dispatch/middleware/request_id.rb
index 303f8e8c23..1555ff72af 100644
--- a/actionpack/lib/action_dispatch/middleware/request_id.rb
+++ b/actionpack/lib/action_dispatch/middleware/request_id.rb
@@ -20,14 +20,16 @@ module ActionDispatch
def call(env)
req = ActionDispatch::Request.new env
- req.request_id = external_request_id(req) || internal_request_id
+ req.request_id = make_request_id(req.x_request_id)
@app.call(env).tap { |_status, headers, _body| headers[X_REQUEST_ID] = req.request_id }
end
private
- def external_request_id(req)
- if request_id = req.x_request_id.presence
+ def make_request_id(request_id)
+ if request_id.presence
request_id.gsub(/[^\w\-]/, "".freeze).first(255)
+ else
+ internal_request_id
end
end