Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / services / api / config / initializers / request_id_middleware.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 module CustomRequestId
6   def make_request_id(req_id)
7     if !req_id || req_id.length < 1 || req_id.length > 1024
8       # Client-supplied ID is either missing or too long to be
9       # considered friendly.
10       internal_request_id
11     else
12       req_id
13     end
14   end
15
16   def internal_request_id
17     "req-" + Random::DEFAULT.rand(2**128).to_s(36)[0..19]
18   end
19 end
20
21 class ActionDispatch::RequestId
22   # Instead of using the default UUID-like format for X-Request-Id headers,
23   # use our own.
24   prepend CustomRequestId
25 end