Add http3 module: HTTP/3 in the Java HTTP Client (JEP 517), opt-in, discovery modes, fallback timings, proxy downgrade and a packet-loss comparison
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KqJyCidz3ZgRyHABv2GVJh
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"""A 25-line HTTP CONNECT proxy, just enough to show that the JDK will not send HTTP/3 through one."""
|
||||
import asyncio, sys
|
||||
|
||||
async def pipe(r, w):
|
||||
try:
|
||||
while data := await r.read(65536):
|
||||
w.write(data); await w.drain()
|
||||
finally:
|
||||
w.close()
|
||||
|
||||
async def handle(cr, cw):
|
||||
line = (await cr.readline()).decode()
|
||||
while (await cr.readline()) not in (b"\r\n", b""):
|
||||
pass
|
||||
method, target, _ = line.split()
|
||||
print("proxy saw:", method, target, flush=True)
|
||||
host, port = target.rsplit(":", 1)
|
||||
ur, uw = await asyncio.open_connection(host, int(port))
|
||||
cw.write(b"HTTP/1.1 200 Connection established\r\n\r\n"); await cw.drain()
|
||||
await asyncio.gather(pipe(cr, uw), pipe(ur, cw))
|
||||
|
||||
async def main():
|
||||
srv = await asyncio.start_server(handle, "127.0.0.1", int(sys.argv[1]))
|
||||
async with srv: await srv.serve_forever()
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user