mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-10-16 00:01:48 -04:00
it was previously only handling 421 status codes for the same effect; this achieves parity with the frame-driven redirection
35 lines
722 B
Ruby
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
|