proxy: request line logged up to 4 KB, added headers written in place

REQMAX is 4 KB: a log line holds 4000 characters, so a longer copy of
the request line was cut by the log before "..." could show.

The headers this proxy adds are written straight after the header
block, HDRRESERVE (2 KB, what they come to at most) asked to be free
there first: in the side's buffer that is the room hdrread() left, so
nothing is copied, and the buffer on the stack they were built in is
gone.

The scheme and authority of a request are no longer kept in a buffer
of their own: req, the line in absolute form as logged, has them, and
where the authority begins and ends in it is kept instead, for the
next request on the connection to be compared with and for a parent
proxy to be given. An authority beyond what req keeps of the line is
refused. A line a request filter rewrote is logged only when the
rewrite is applied.

Tests: a 5 KB line through a parent arrives whole in absolute form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir DubrovinandClaude Opus 5.5 committed 2026-10-19 11:20:45 +03:00
1 parent 96adc6d9cd
commit 63a736c693
2 files changed
+106 -104

No files matched your search

+12 -3
View File
@@ -203,7 +203,7 @@ def run(t):
t.fail("its line is in absolute form, put together with the headers", want, head[:120])
t.eq(body, rbody, "and its body whole")
# --- a long request line: served whole, logged up to REQMAX (6 KB) ----
# --- a long request line: served whole, logged cut at REQMAX (4 KB) ---
origin.answer = ok
origin.requests.clear()
got = session(proxy, request(b"/" + b"q" * 7000), 1)
@@ -214,11 +214,20 @@ def run(t):
deadline = time.time() + 3
while time.time() < deadline and "q" * 3000 not in server.output():
time.sleep(0.1)
# the log line holds 4000 characters (log.c): cut there before REQMAX
logged = [l for l in server.output().splitlines() if "qqqq" in l]
t.ok("and it is logged, cut") if logged and "q" * 7000 not in logged[-1] else \
t.ok("and it is logged, cut") if logged and "q" * 4100 not in logged[-1] else \
t.fail("and it is logged, cut", "a log line", logged[-1][-60:] if logged else None)
# through a parent: authority put back from the log copy, a path long
# enough for that copy to be cut
origin.requests.clear()
got = session(viaparent, request(b"/" + b"r" * 5000), 1)
t.contains(got.decode("latin-1"), "200 OK", "a 5 KB line through a parent is answered")
head = origin.requests[0][0] if origin.requests else b""
want = b"GET " + base.encode() + b"/" + b"r" * 5000 + b" HTTP/1.1\r\n"
t.ok("in absolute form, whole") if head.startswith(want) else \
t.fail("in absolute form, whole", "GET http://.../rrr", head[:80])
# --- a request too big for any buffer is refused, and the proxy stays --
huge = b"".join(b"X-Huge-%d: %s\r\n" % (i, b"H" * 30000) for i in range(20))
got = session(proxy, request(b"/huge", huge), 1, timeout=3)