Method: ActionDispatch::Http::URL#optional_port

Defined in:
actionpack/lib/action_dispatch/http/url.rb

#optional_portObject

Returns a number port suffix like 8080 if the port number of this request is not the default HTTP port 80 or HTTPS port 443.

req = ActionDispatch::Request.new 'HTTP_HOST' => 'example.com:80'
req.optional_port # => nil

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


294
295
296
# File 'actionpack/lib/action_dispatch/http/url.rb', line 294

def optional_port
  standard_port? ? nil : port
end