module ActionDispatch::Http::URL

def standard_port

req.standard_port # => 80
req = ActionDispatch::Request.new 'HTTP_HOST' => 'example.com:8080'

Returns the standard \port number for this request's protocol.
def standard_port
  if "https://" == protocol
    443
  else
    80
  end
end