Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way to add .headers for .any.js tests #23268

Closed
RReverser opened this issue Apr 27, 2020 · 3 comments
Closed

No way to add .headers for .any.js tests #23268

RReverser opened this issue Apr 27, 2020 · 3 comments

Comments

@RReverser
Copy link
Contributor

I'm trying to add an [testname].any.js test that relies on certain headers set on the page, but struggling.

It seems that [testname].any.js.headers applies to [testname].any.js itself, and even manual expansions to [testname].any.html.headers and [testname].any.worker.html.headers are ignored even though match names of autogenerated HTMLs.

/cc @Ms2ger

@Ms2ger
Copy link
Contributor

Ms2ger commented Apr 28, 2020

The autogenerated "files" are produced by tools/serve's WrapperHandler, with headers added here:

wpt/tools/serve/serve.py

Lines 74 to 76 in 896db56

def handle_request(self, request, response):
for header_name, header_value in self.headers:
response.headers.set(header_name, header_value)

The .headers support is in tools/wptserve's FileHandler here:

def get_headers(self, request, path):
rv = (self.load_headers(request, os.path.join(os.path.split(path)[0], "__dir__")) +
self.load_headers(request, path))
if not any(key.lower() == b"content-type" for (key, _) in rv):
rv.insert(0, (b"Content-Type", guess_content_type(path).encode("ascii")))
return rv
def load_headers(self, request, path):
headers_path = path + ".sub.headers"
if os.path.exists(headers_path):
use_sub = True
else:
headers_path = path + ".headers"
use_sub = False
try:
with open(headers_path, "rb") as headers_file:
data = headers_file.read()
except IOError:
return []
else:
if use_sub:
data = template(request, data, escape_type="none")
return [tuple(item.strip() for item in line.split(b":", 1))
for line in data.splitlines() if line]

It seems like it should not be an unreasonable amount of work to factor the latter code out of the FileHandler class (it doesn't depend on self) and make WrapperHandler use it.

@hiroshige-g
Copy link
Contributor

Related to (and maybe fixed by): #26014

@Ms2ger
Copy link
Contributor

Ms2ger commented May 27, 2021

Thanks for the pointer, looks like it's working indeed.

@Ms2ger Ms2ger closed this as completed May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants