mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-10 00:01:27 -04:00
extending URI to include non ascii hostname attribute; added own custom uri initialization function, which performs additional checks when needed
This commit is contained in:
parent
cbfb5c968e
commit
f9c1d7de44
@ -56,9 +56,17 @@ module HTTPX
|
||||
|
||||
module URIExtensions
|
||||
refine URI::Generic do
|
||||
def non_ascii_hostname
|
||||
@non_ascii_hostname
|
||||
end
|
||||
|
||||
def non_ascii_hostname=(hostname)
|
||||
@non_ascii_hostname = hostname
|
||||
end
|
||||
|
||||
def authority
|
||||
port_string = port == default_port ? nil : ":#{port}"
|
||||
"#{host}#{port_string}"
|
||||
"#{@non_ascii_hostname || host}#{port_string}"
|
||||
end
|
||||
|
||||
def origin
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
module HTTPX
|
||||
module Utils
|
||||
using URIExtensions
|
||||
|
||||
module_function
|
||||
|
||||
# The value of this field can be either an HTTP-date or a number of
|
||||
@ -14,5 +16,19 @@ module HTTPX
|
||||
time = Time.httpdate(retry_after)
|
||||
time - Time.now
|
||||
end
|
||||
|
||||
def uri(uri)
|
||||
return Kernel.URI(uri) unless uri.is_a?(String) && !uri.ascii_only?
|
||||
|
||||
uri = Kernel.URI(URI.escape(uri))
|
||||
|
||||
non_ascii_hostname = URI.unescape(uri.host)
|
||||
|
||||
idna_hostname = DomainName.new(non_ascii_hostname).hostname
|
||||
|
||||
uri.host = idna_hostname
|
||||
uri.non_ascii_hostname = non_ascii_hostname
|
||||
uri
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user