Module: Gitlab::Logging::CloudflareHelper

Included in:
ApplicationController, GrapeLogging::Loggers::CloudflareLogger, Gitlab::Lograge::CustomOptions
Defined in:
lib/gitlab/logging/cloudflare_helper.rb

Constant Summary collapse

CLOUDFLARE_CUSTOM_HEADERS =
{ 'Cf-Ray' => :cf_ray, 'Cf-Request-Id' => :cf_request_id }.freeze

Instance Method Summary collapse

Instance Method Details

#store_cloudflare_headers!(payload, request) ⇒ Object



8
9
10
11
12
# File 'lib/gitlab/logging/cloudflare_helper.rb', line 8

def store_cloudflare_headers!(payload, request)
  CLOUDFLARE_CUSTOM_HEADERS.each do |header, value|
    payload[value] = request.headers[header] if valid_cloudflare_header?(request.headers[header])
  end
end

#valid_cloudflare_header?(value) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/gitlab/logging/cloudflare_helper.rb', line 14

def valid_cloudflare_header?(value)
  return false unless value.present?
  return false if value.length > 64
  return false if value.index(/[^[A-Za-z0-9-]]/)

  true
end