lychee/fixtures/fragments
MichaIng 92a9bca23f
feat: skip fragment checking for unsupported MIME types (#1744)
* feat: skip fragment checking for unsupported MIME types

The remote URL/website checker currently passes all URLs with fragments to the fragment checker as HTML document, even if it is a different or unsupported MIME type. This can cause false fragment checking for Markdown documents, failures for other MIME types, especially binaries, and unnecessary traffic for large downloads, which are always finished completely, if the fragment checker is invoked.

This commit checks the Content-Type header of the response:
- Only if it is `text/html`, it is passed to the fragment checker as HTML type.
- Only if it is `text/markdown`, of `text/plain` and URL path ends on `.md`, it is passed to the fragment checker as Markdown type.
- In all other cases, the fragment checker is skipped and the HTTP status is returned.

To invoke the fragment checker with a variable document type, a new `FileType` argument is added to the `check_html_fragment()` function.

The fragment checker test and fixture are adjusted to match the expected result: checking a binary file via remote URL with fragment is now expected to succeed, since its Content-Type header does not invoke the fragment checker anymore.

Signed-off-by: MichaIng <micha@dietpi.com>

* Update fixtures/fragments/file1.md

Co-authored-by: MichaIng <micha@dietpi.com>

---------

Signed-off-by: MichaIng <micha@dietpi.com>
Co-authored-by: Matthias Endler <matthias@endler.dev>
2025-07-06 10:46:06 +02:00
..
empty_dir fix: only check the fragment when it's a file (#1713) 2025-05-23 21:50:26 +02:00
sub_dir fix: treat a fragment in an empty directory as an error (#1756) 2025-07-04 10:25:57 +02:00
empty_file Introduce fragment checking for links to markdown files. (#1126) 2023-07-31 16:04:00 +02:00
file.html feat: add 'user-content-' prefix to support github markdown fragment (#1750) 2025-07-04 22:58:47 +02:00
file1.md feat: skip fragment checking for unsupported MIME types (#1744) 2025-07-06 10:46:06 +02:00
file2.md Decode percent escapes in fragments (#1275) 2024-01-05 15:46:09 +01:00
zero.bin fix: skip fragment check if website URL doesn't contain fragment (#1733) 2025-06-20 17:47:35 +02:00