fix(wpt): serve the XHR request-header echo fixture

This commit is contained in:
ldm0
2026-09-27 07:59:24 +08:00
parent 51b7049086
commit 6dbe36ea07
2 changed files with 10 additions and 2 deletions
@@ -819,7 +819,7 @@ def _empty_location_handler_reference_patterns(directory: str) -> tuple[re.Patte
def _xhr_handler_reference_patterns(directory: str) -> tuple[re.Pattern[str], ...]:
references = []
for name in (
"requri.py", "redirect.py", "inspect-headers.py", "content.py",
"requri.py", "redirect.py", "inspect-headers.py", "echo-headers.py", "content.py",
"echo-content-type.py", "win-1252-xml.py", "win-1252-html.py",
"invalid-utf8-html.py", "shift-jis-html.py", "img-utf8-html.py",
"empty-div-utf8-html.py", "status.py", "last-modified.py",
@@ -116,6 +116,7 @@ XHR_RESOURCE_PATHS = {
"/xhr/resources/requri.py",
"/xhr/resources/redirect.py",
"/xhr/resources/inspect-headers.py",
"/xhr/resources/echo-headers.py",
"/xhr/resources/content.py",
"/xhr/resources/echo-content-type.py",
"/xhr/resources/status.py",
@@ -2943,6 +2944,11 @@ def _make_handler(
headers, body = _xhr_inspect_headers_fixture_response(
parsed.query, list(self.headers.raw_items())
)
elif path == "/xhr/resources/echo-headers.py":
status, reason = 200, None
headers = [("Content-Type", "text/plain")]
# wptserve exposes the same HTTPMessage as raw_headers.
body = str(self.headers).encode("utf-8")
elif path == "/xhr/resources/content.py":
params = parse_qs(parsed.query, keep_blank_values=True, encoding="latin-1")
if "content" in params:
@@ -2997,7 +3003,9 @@ def _make_handler(
return True
# Close connections with unread uploads so early responses and
# redirects do not wait for the request body to finish.
if path == "/xhr/resources/echo-content-type.py" or not upload_consumed and (
if path in {
"/xhr/resources/echo-content-type.py", "/xhr/resources/echo-headers.py"
} or not upload_consumed and (
self.headers.get("Transfer-Encoding") is not None
or self.headers.get("Content-Length", "0").strip() not in {"", "0"}
):