Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
URI::HTTP#authority
() -> ::String
authority
lib/uri/http.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/uri/http.rb, line 109
def authority
if port == default_port
host
else
"#{host}:#{port}"
end
end
Description
Returns the authority for an HTTP uri, as defined in www.rfc-editor.org/rfc/rfc3986#section-3.2.
Example:
Example
URI::HTTP.build(host: 'www.example.com', path: '/foo/bar').authority #=> "www.example.com" URI::HTTP.build(host: 'www.example.com', port: 8000, path: '/foo/bar').authority #=> "www.example.com:8000" URI::HTTP.build(host: 'www.example.com', port: 80, path: '/foo/bar').authority #=> "www.example.com"