httpx/test/support/servlets/misdirected.rb
HoneyryderChuck a437de36e8 handle HTTP_1_1_REQUIRED stream GOAWAY error code by retrying on new HTTP/1.1 connection
it was previously only handling 421 status codes for the same effect; this achieves parity with the frame-driven redirection
2025-03-19 23:11:51 +00:00

35 lines
722 B
Ruby

# frozen_string_literal: true
class MisdirectedServer < TestHTTP2Server
attr_reader :frames
def initialize
super
@server.ctx.alpn_select_cb = lambda do |protocols|
protocols.first
end
end
private
def handle_connection(conn, sock)
case sock.alpn_protocol
when "h2"
super
conn.on(:frame_received) do |_|
conn.goaway(:http_1_1_required)
end
else
# HTTP/1
# read request payload until \r\n
loop do
data = sock.readpartial(2048)
break if data.end_with?("\r\n")
end
sock.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConten-length: 3\r\nConnection: close\r\n\r\nfoo")
sock.close
end
end
end