lib/zold/http.rb in zold-0.16.20 vs lib/zold/http.rb in zold-0.16.21
- old
+ new
@@ -20,11 +20,10 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
require 'rainbow'
require 'uri'
-require 'timeout'
require 'net/http'
require 'backtrace'
require 'zold/score'
require_relative 'version'
@@ -54,49 +53,47 @@
# protocol.
PROTOCOL_HEADER = 'X-Zold-Protocol'
# Read timeout in seconds
READ_TIMEOUT = 1
+ private_constant :READ_TIMEOUT
# Connect timeout in seconds
CONNECT_TIMEOUT = 0.4
+ private_constant :CONNECT_TIMEOUT
def initialize(uri:, score: Score::ZERO, network: 'test')
@uri = uri.is_a?(URI) ? uri : URI(uri)
@score = score
@network = network
end
- def get(timeout: Http::READ_TIMEOUT + Http::CONNECT_TIMEOUT)
+ def get(timeout: READ_TIMEOUT + CONNECT_TIMEOUT)
http = Net::HTTP.new(@uri.host, @uri.port)
http.use_ssl = @uri.scheme == 'https'
http.read_timeout = timeout
- http.open_timeout = Http::CONNECT_TIMEOUT
+ http.open_timeout = CONNECT_TIMEOUT
path = @uri.path
path += '?' + @uri.query if @uri.query
- Timeout.timeout(timeout + Http::CONNECT_TIMEOUT) do
- http.request_get(path, headers)
- end
+ http.request_get(path, headers)
rescue StandardError => e
Error.new(e)
end
- def put(body, timeout: Http::READ_TIMEOUT + Http::CONNECT_TIMEOUT)
+ def put(body, timeout: READ_TIMEOUT + CONNECT_TIMEOUT)
http = Net::HTTP.new(@uri.host, @uri.port)
http.use_ssl = @uri.scheme == 'https'
http.read_timeout = timeout
- http.open_timeout = Http::CONNECT_TIMEOUT
+ http.open_timeout = CONNECT_TIMEOUT
path = @uri.path
path += '?' + @uri.query if @uri.query
- Timeout.timeout(timeout + Http::CONNECT_TIMEOUT) do
- http.request_put(
- path, body,
- headers.merge(
- 'Content-Type': 'text/plain',
- 'Content-Length': body.length.to_s
- )
+ http.request_put(
+ path, body,
+ headers.merge(
+ 'Content-Type': 'text/plain',
+ 'Content-Length': body.length.to_s
)
- end
+ )
rescue StandardError => e
Error.new(e)
end
private