httpx/test/support/servlets/by_ip_cert_server.rb
HoneyryderChuck 57629cb9b0 fix: do not check if multi-homed network at boot time, instead do it a runtime
this requires calling , which calls the  syscall, which may be blocked at boot time in certain constrained environments

this is moved into a module function, which memoizes the result; it's done in a non-thread safe way, but since the result is expected to be the same, it should be ok to race
2025-09-22 15:45:08 +01:00

23 lines
644 B
Ruby

# frozen_string_literal: true
require_relative "test"
class ByIpCertServer < TestServer
CERTS_DIR = File.expand_path("../ci/certs", __dir__)
def initialize
cert = OpenSSL::X509::Certificate.new(File.read(File.join(CERTS_DIR, "localhost-server.crt")))
key = OpenSSL::PKey.read(File.read(File.join(CERTS_DIR, "localhost-server.key")))
super(
:BindAddress => HTTPX::Resolver.supported_ip_families.size > 1 ? "::1" : "127.0.0.1",
:SSLEnable => true,
:SSLCertificate => cert,
:SSLPrivateKey => key,
)
mount_proc("/") do |_req, res|
res.status = 200
res.body = "hello"
end
end
end