mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-13 08:08:31 +00:00
Move Crystal stdlib classes overrides to a separate file
This commit is contained in:
parent
c76bd7b45b
commit
6bdcd9e96c
49
src/invidious/helpers/crystal_class_overrides.cr
Normal file
49
src/invidious/helpers/crystal_class_overrides.cr
Normal file
@ -0,0 +1,49 @@
|
||||
class TCPSocket
|
||||
def initialize(host, port, dns_timeout = nil, connect_timeout = nil, family = Socket::Family::UNSPEC)
|
||||
Addrinfo.tcp(host, port, timeout: dns_timeout, family: family) do |addrinfo|
|
||||
super(addrinfo.family, addrinfo.type, addrinfo.protocol)
|
||||
connect(addrinfo, timeout: connect_timeout) do |error|
|
||||
close
|
||||
error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class HTTP::Client
|
||||
property family : Socket::Family = Socket::Family::UNSPEC
|
||||
|
||||
private def socket
|
||||
socket = @socket
|
||||
return socket if socket
|
||||
|
||||
hostname = @host.starts_with?('[') && @host.ends_with?(']') ? @host[1..-2] : @host
|
||||
socket = TCPSocket.new hostname, @port, @dns_timeout, @connect_timeout, @family
|
||||
socket.read_timeout = @read_timeout if @read_timeout
|
||||
socket.sync = false
|
||||
|
||||
{% if !flag?(:without_openssl) %}
|
||||
if tls = @tls
|
||||
socket = OpenSSL::SSL::Socket::Client.new(socket, context: tls, sync_close: true, hostname: @host)
|
||||
end
|
||||
{% end %}
|
||||
|
||||
@socket = socket
|
||||
end
|
||||
end
|
||||
|
||||
class HTTP::Server::Response
|
||||
class Output
|
||||
private def unbuffered_flush
|
||||
@io.flush
|
||||
rescue ex : IO::Error
|
||||
unbuffered_close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class PG::ResultSet
|
||||
def field(index = @column_index)
|
||||
@fields.not_nil![index]
|
||||
end
|
||||
end
|
@ -509,12 +509,6 @@ def check_table(db, table_name, struct_type = nil)
|
||||
end
|
||||
end
|
||||
|
||||
class PG::ResultSet
|
||||
def field(index = @column_index)
|
||||
@fields.not_nil![index]
|
||||
end
|
||||
end
|
||||
|
||||
def get_column_array(db, table_name)
|
||||
column_array = [] of String
|
||||
db.query("SELECT * FROM #{table_name} LIMIT 0") do |rs|
|
||||
@ -699,47 +693,3 @@ def proxy_file(response, env)
|
||||
IO.copy response.body_io, env.response
|
||||
end
|
||||
end
|
||||
|
||||
class HTTP::Server::Response
|
||||
class Output
|
||||
private def unbuffered_flush
|
||||
@io.flush
|
||||
rescue ex : IO::Error
|
||||
unbuffered_close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class HTTP::Client
|
||||
property family : Socket::Family = Socket::Family::UNSPEC
|
||||
|
||||
private def socket
|
||||
socket = @socket
|
||||
return socket if socket
|
||||
|
||||
hostname = @host.starts_with?('[') && @host.ends_with?(']') ? @host[1..-2] : @host
|
||||
socket = TCPSocket.new hostname, @port, @dns_timeout, @connect_timeout, @family
|
||||
socket.read_timeout = @read_timeout if @read_timeout
|
||||
socket.sync = false
|
||||
|
||||
{% if !flag?(:without_openssl) %}
|
||||
if tls = @tls
|
||||
socket = OpenSSL::SSL::Socket::Client.new(socket, context: tls, sync_close: true, hostname: @host)
|
||||
end
|
||||
{% end %}
|
||||
|
||||
@socket = socket
|
||||
end
|
||||
end
|
||||
|
||||
class TCPSocket
|
||||
def initialize(host, port, dns_timeout = nil, connect_timeout = nil, family = Socket::Family::UNSPEC)
|
||||
Addrinfo.tcp(host, port, timeout: dns_timeout, family: family) do |addrinfo|
|
||||
super(addrinfo.family, addrinfo.type, addrinfo.protocol)
|
||||
connect(addrinfo, timeout: connect_timeout) do |error|
|
||||
close
|
||||
error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user