Skip to content

Commit

Permalink
Fix to changes in HTTP::Client
Browse files Browse the repository at this point in the history
  • Loading branch information
mamantoha committed Apr 24, 2024
1 parent 20beb3a commit 9315939
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/crest.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ require "base64"
require "http-client-digest_auth"
require "http_proxy"
require "./ext/io"
require "./ext/int"
require "./ext/float"
require "./ext/http/cookie"

# This module's static methods are the entry point for using the Crest client.
Expand Down
12 changes: 9 additions & 3 deletions src/crest/request.cr
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,15 @@ module Crest
end

private def set_timeouts!
@read_timeout.try { |timeout| @http_client.read_timeout = timeout }
@write_timeout.try { |timeout| @http_client.write_timeout = timeout }
@connect_timeout.try { |timeout| @http_client.connect_timeout = timeout }
@read_timeout.try { |timeout| @http_client.read_timeout = timeout_to_time_span(timeout) }
@write_timeout.try { |timeout| @http_client.write_timeout = timeout_to_time_span(timeout) }
@connect_timeout.try { |timeout| @http_client.connect_timeout = timeout_to_time_span(timeout) }
end

private def timeout_to_time_span(timeout : Crest::TimeoutValue) : Time::Span
return timeout if timeout.is_a?(Time::Span)

timeout.to_time_span
end

# Extract the query parameters and append them to the `url`
Expand Down
8 changes: 8 additions & 0 deletions src/ext/float.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct Float
def to_time_span : Time::Span
seconds = self.to_i
nanoseconds = ((self - seconds) * 1_000_000_000).to_i

Time::Span.new(seconds: seconds, nanoseconds: nanoseconds)
end
end
5 changes: 5 additions & 0 deletions src/ext/int.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
struct Int
def to_time_span : Time::Span
Time::Span.new(seconds: self)
end
end

0 comments on commit 9315939

Please sign in to comment.