mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-14 00:28:31 +00:00
Update crystal overrides for HTTP::Client socket
This commit is contained in:
parent
dfd660ca72
commit
33c62b9b8e
@ -18,22 +18,33 @@ end
|
|||||||
class HTTP::Client
|
class HTTP::Client
|
||||||
property family : Socket::Family = Socket::Family::UNSPEC
|
property family : Socket::Family = Socket::Family::UNSPEC
|
||||||
|
|
||||||
private def socket
|
private def io
|
||||||
socket = @socket
|
io = @io
|
||||||
return socket if socket
|
return io if io
|
||||||
|
unless @reconnect
|
||||||
|
raise "This HTTP::Client cannot be reconnected"
|
||||||
|
end
|
||||||
|
|
||||||
hostname = @host.starts_with?('[') && @host.ends_with?(']') ? @host[1..-2] : @host
|
hostname = @host.starts_with?('[') && @host.ends_with?(']') ? @host[1..-2] : @host
|
||||||
socket = TCPSocket.new hostname, @port, @dns_timeout, @connect_timeout, @family
|
io = TCPSocket.new hostname, @port, @dns_timeout, @connect_timeout, @family
|
||||||
socket.read_timeout = @read_timeout if @read_timeout
|
io.read_timeout = @read_timeout if @read_timeout
|
||||||
socket.sync = false
|
io.write_timeout = @write_timeout if @write_timeout
|
||||||
|
io.sync = false
|
||||||
|
|
||||||
{% if !flag?(:without_openssl) %}
|
{% if !flag?(:without_openssl) %}
|
||||||
if tls = @tls
|
if tls = @tls
|
||||||
socket = OpenSSL::SSL::Socket::Client.new(socket, context: tls, sync_close: true, hostname: @host)
|
tcp_socket = io
|
||||||
|
begin
|
||||||
|
io = OpenSSL::SSL::Socket::Client.new(tcp_socket, context: tls, sync_close: true, hostname: @host)
|
||||||
|
rescue exc
|
||||||
|
# don't leak the TCP socket when the SSL connection failed
|
||||||
|
tcp_socket.close
|
||||||
|
raise exc
|
||||||
|
end
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
@socket = socket
|
@io = io
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user