Module: HTTPX::Utils

Defined in:
lib/httpx/utils.rb

Constant Summary collapse

URIParser =
URI::RFC2396_Parser.new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.elapsed_time(monotonic_timestamp) ⇒ Object



13
14
15
# File 'lib/httpx/utils.rb', line 13

def elapsed_time(monotonic_timestamp)
  Process.clock_gettime(Process::CLOCK_MONOTONIC) - monotonic_timestamp
end

.nowObject



9
10
11
# File 'lib/httpx/utils.rb', line 9

def now
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
end

.parse_retry_after(retry_after) ⇒ Object

The value of this field can be either an HTTP-date or a number of seconds to delay after the response is received.



19
20
21
22
23
24
25
26
# File 'lib/httpx/utils.rb', line 19

def parse_retry_after(retry_after)
  # first: bet on it being an integer
  Integer(retry_after)
rescue ArgumentError
  # Then it's a datetime
  time = Time.httpdate(retry_after)
  time - Time.now
end

Instance Method Details

#to_uri(uri) ⇒ Object



30
31
32
# File 'lib/httpx/utils.rb', line 30

def to_uri(uri)
  URI(uri)
end