Fix rewrite and over-long header handling on Windows

op_rewrite checked what it built with targetunsafe(), which describes a
path on this machine: on Windows it must name a drive or a share, so a
rewritten request path was refused and every rewrite rule failed there.
A rewrite produces a request path and is checked as one.

The header loop stopped at HTTPSRV_MAXHDR and answered anyway, leaving
the rest of the request in the stream for the next one to be read out
of. It refuses the request instead. A header longer than the buffer
arrives as several lines, so the count bounds what is read rather than
what a client may send in one header.

The test for the buffer growth after a PCRE rewrite sent its request
through to an httpsrv origin, which stops reading at that same cap; it
uses an origin which reads whatever it is sent, since what is under test
is the proxy in the middle.
This commit is contained in:
Vladimir Dubrovin committed 2026-08-29 20:21:29 +03:00
1 parent 7eca490bf3
commit 32a5e1e6ab
3 files changed
+43 -14

No files matched your search

+11 -4
View File
@@ -375,12 +375,14 @@ class Tester:
text, _ = self.raw_session(pport, request, host=phost, quiet=2)
return text
def raw_server(self, port, reply, close_after=True, host="127.0.0.1"):
def raw_server(self, port, reply, close_after=True, host="127.0.0.1",
drain=False):
"""Answer every connection with fixed bytes. Returns a stop function.
For the shapes a real server would have to be talked into: an answer
whose body is delimited by the close, or one which promises to stay
and does not.
and does not. drain reads the whole request first, however large,
which is what a test of the sending side needs.
"""
sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@@ -395,8 +397,13 @@ class Tester:
except OSError:
break
try:
conn.settimeout(self.timeout)
conn.recv(65536)
conn.settimeout(0.5 if drain else self.timeout)
while True:
try:
if not conn.recv(65536) or not drain:
break
except socket.timeout:
break # it has stopped sending
conn.sendall(reply)
if close_after:
conn.close()