Fix mimetype for PDF.js files on Windows
With windows-2022 and windows-2025 on GitHub Actions,
we get:
qutescheme:data_for_url:128 url: qute://pdfjs/web/viewer.mjs, path: /web/viewer.mjs, host pdfjs
webenginequtescheme:requestStarted:105 Returning text/plain data
which causes:
JS: [qute://pdfjs/build/pdf.mjs:0] Failed to load module script: Expected a
JavaScript module script but the server responded with a MIME type of
"text/plain". Strict MIME type checking is enforced for module scripts per
HTML spec.
It's unclear why we get text/plain back there in the first place (can't
reproduce on a local Windows 11 install), but it's definitely wrong, so let's
just override that problematic case.
This commit is contained in:
parent
9219869cb9
commit
3f31a0005a
|
|
@ -722,6 +722,11 @@ def guess_mimetype(filename: str, fallback: bool = False) -> str:
|
|||
fallback: Fall back to application/octet-stream if unknown.
|
||||
"""
|
||||
mimetype, _encoding = mimetypes.guess_type(filename)
|
||||
if os.path.splitext(filename)[1] == '.mjs' and mimetype == "text/plain":
|
||||
# For unknown reasons, Windows (at least on GitHub Actions) wrongly
|
||||
# gives us text/plain here.
|
||||
return "text/javascript"
|
||||
|
||||
if mimetype is None:
|
||||
if fallback:
|
||||
return 'application/octet-stream'
|
||||
|
|
|
|||
|
|
@ -858,6 +858,7 @@ def test_chunk_invalid(n):
|
|||
@pytest.mark.parametrize('filename, expected', [
|
||||
('test.jpg', 'image/jpeg'),
|
||||
('test.blabla', 'application/octet-stream'),
|
||||
('test.mjs', 'text/javascript'),
|
||||
])
|
||||
def test_guess_mimetype(filename, expected):
|
||||
assert utils.guess_mimetype(filename, fallback=True) == expected
|
||||
|
|
|
|||
Loading…
Reference in New Issue