httpx/test/support/keep_alive_server.rb
HoneyryderChuck e6c9bb4714 fix: http/1.1 recover from connection exhausted
While adding the test, the code to recover from an exhausted HTTP/1.1
connection proved not to be reliable, as it wasn't taking inflight
requests nor update-once keep-alive max requests counters into
account.

This has been fixed by implementing our own test dummy using
webrick.
2020-11-26 20:11:30 +00:00

35 lines
796 B
Ruby

# frozen_string_literal: true
require "webrick"
require "logger"
class KeepAliveServer < WEBrick::HTTPServer
class KeepAliveApp < WEBrick::HTTPServlet::AbstractServlet
SOCKS = [].freeze
def do_GET(_req, res) # rubocop:disable Naming/MethodName
res.status = 200
res["Connection"] = "Keep-Alive"
res["Keep-Alive"] = "max=2"
res["Content-Type"] = "application/json"
res.body = "{\"counter\": 2}"
end
end
def initialize(options = {})
super({
:BindAddress => "127.0.0.1",
:Port => 0,
:AccessLog => File.new(File::NULL),
:Logger => Logger.new(File::NULL),
}.merge(options))
mount("/", KeepAliveApp)
end
def origin
sock = listeners.first
_, sock, ip, _ = sock.addr
"http://#{ip}:#{sock}"
end
end