Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change URI#to_s to handle default ports for more schemes than http/ht…
…tps (crystal-lang#5233) * Change URI#to_s to handle default ports for more schemes than http/https * Change DEFAULT_PORTS to be a constant rather than class variable * Rename method to default_port? and move nil check back to #to_s * Remove unnecessary return statement from default_port? method * Add URI.default_ports method, which allows for default ports to be queried, registered, and unregistered, as follows. Query the default port for a given scheme: URI.default_ports["http"] #=> 80 URI.default_ports["ponzi"] #=> nil Register a default port for a given scheme: URI.default_ports["ponzi"] = 9999 URI.default_ports["ponzi"] #=> 9999 Unregister a default port for a given scheme: URI.default_ports["ftp"] #=> 21 URI.default_ports["ftp"] = nil URI.default_ports["ftp"] #=> nil * Fix URI::DefaultPorts#[]= to downcase scheme on delete * Add URI.default_port method for returning a scheme's the default port URI.default_port "http" # => 80 URI.default_port "ponzi" # => nil * Rename URI.default_ports method to URI.default_port, allowing default ports to be accessed via either a hash like accessor or getter method with consistent naming: URI.default_port "http" # => 80 URI.default_port["http"] # => 80 * Fix method comments to use back ticks consistently * Change DefaultPort class to use instance variable rather than class variable for the internal hash of default ports, and to be more hash like for unregistering a default port via the new delete method * Simplify to use two methods: URI.default_port and URI.set_default_port * Fix the method documentation formatting * Add more well-known default ports sourced from IANA via Mahmoud's [scheme_port_map.json][1] [1]: https://gist.github.com/mahmoud/2fe281a8daaff26cfe9c15d2c5bf5c8b * Fix #default_port? to correctly handle nil scheme * Change URI default port API to return a mutable subclass of Hash with case-insensitive keys * Change DefaultPortHash seeding to use merge! method * Fix default_port? to not call scheme.downcase unnecessarily * Add spec for URI with nil scheme and non-nil port * Change DefaultPortHash seeds to be an initialize parameter * Fix DefaultPortHash case insensitive keys for methods other than []= and fetch * Revert to using two methods: URI.default_port and URI.set_default_port * Fix typo in URI.default_port comment * Fix typo in URI.set_default_port comment * Fix URI.set_default_port comment formatting for scheme parameter * Fix URI#default_port? to be thread safe * Change URI.set_default_port to always return nil
- Loading branch information