module Rack::Request::Helpers

def wrap_ipv6(host)

Assist with compatibility when processing `X-Forwarded-For`.
def wrap_ipv6(host)
  # Even thought IPv6 addresses should be wrapped in square brackets,
  # sometimes this is not done in various legacy/underspecified headers.
  # So we try to fix this situation for compatibility reasons.
  # Try to detect IPv6 addresses which aren't escaped yet:
  if !host.start_with?('[') && host.count(':') > 1
    "[#{host}]"
  else
    host
  end
end