Skip to content

Commit

Permalink
tool: serve: ignore link headers with prefetches and preloads
Browse files Browse the repository at this point in the history
  • Loading branch information
oxij committed Dec 29, 2024
1 parent 5f1afdf commit 55753d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tool/hoardy_web/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2685,6 +2685,12 @@ def rebase_remap_url(url : URLType) -> URLType | None:
else:
links = []
for url, params in plinks:
rel = get_parameter_value(params, "rel", None)
if rel is not None:
allowed_rels = link_rels_of(rel, blacklist=preload_link_rels)
if len(allowed_rels) == 0:
continue
params = set_parameter(params, "rel", " ".join(allowed_rels))
href = rebase_remap_url(url)
if href is not None:
links.append((href, params))
Expand Down
4 changes: 2 additions & 2 deletions tool/hoardy_web/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class CSSScrubbingError(Failure): pass
(htmlns_video, src_attr): (LinkType.REQ, video_mime + audio_video_mime),
}

prefetch_link_rels = frozenset([
preload_link_rels = frozenset([
"dns-prefetch", "preconnect", "prefetch", "prerender", "preload", "modulepreload",
])

Expand Down Expand Up @@ -454,7 +454,7 @@ def make_scrubbers(opts : ScrubbingOptions) -> Scrubbers:
if not opts.styles:
link_rel_blacklist.update(stylesheet_link_rels)
if not opts.prefetches:
link_rel_blacklist.update(prefetch_link_rels)
link_rel_blacklist.update(preload_link_rels)

jumps = opts.jumps
actions = opts.actions
Expand Down

0 comments on commit 55753d6

Please sign in to comment.