Skip to content

Commit cc40544

Browse files
committed
Refactor to use RFC parser
1 parent 3179129 commit cc40544

File tree

1 file changed

+56
-129
lines changed

1 file changed

+56
-129
lines changed

source

Lines changed: 56 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -14246,149 +14246,76 @@ interface <dfn interface>HTMLLinkElement</dfn> : <span>HTMLElement</span> {
1424614246
"<code data-x="">media</code>" <var>phase</var>:</p>
1424714247

1424814248
<ol>
14249-
<li><p>Let <var>linkHeaders</var> be the result of <span
14250-
data-x="concept-header-list-get-decode-split">getting, decoding, and splitting</span>
14251-
`<code>Link</code>` from <var>response</var>'s
14252-
<span data-x="concept-response-header-list">header list</span>.</p></li>
14249+
<li><p>Let <var>linkObjects</var> be the result of parsing link headers given
14250+
<var>response</var>'s <span data-x="concept-response-header-list">header list</span>, as defined
14251+
in <a href="https://datatracker.ietf.org/doc/html/rfc8288#appendix-B.1">RFC 8288 appendix B.1</a>.</p></li>
1425314252

14254-
<li><p>If <var>linkHeaders</var> is null, then return.</p></li>
14255-
14256-
<li>
14257-
<p><span data-x="list iterate">For each</span> <var>rawLink</var> of
14258-
<var>linkHeaders</var>, run these steps:</p>
14259-
14260-
<ol>
14261-
<li><p>Let (<var>href</var>, <var>params</var>) be the result of
14262-
<span data-x="parse a link header"> parsing</span> <var>linkHeader</var>.
14263-
according to the `<code data-x="http-link">Link</code>` header
14264-
14265-
<li>
14266-
<p>If <var>params</var>["<code data-x="attr-link-rel">rel</code>"] is not
14267-
"<code data-x="rel-preload">preload</code>", then <span>continue</span>.</p>
14268-
14269-
<p class=note>Additional support for link types can be added here in the future.</p>
14270-
</li>
14271-
14272-
<li><p>Let <var>expectedPhase</var> be "<code data-x="">media</code>" if either
14273-
"<code data-x="attr-img-srcset">srcset</code>",
14274-
"<code data-x="attr-link-imagesrcset">imagesrcset</code>", or <code
14275-
data-x="attr-link-media">media</code>" <span data-x="map exists">exist</span> in
14276-
<var>params</var>; otherwise false.</p></li>
14277-
14278-
<li><p>If <var>expectedPhase</var> is not <var>phase</var>, then
14279-
<span>continue</span>.</p></li>
14280-
14281-
<li><p>If <var>params</var> includes "<code data-x="attr-link-media">media</code>" and
14282-
<var>params</var>["<code data-x="attr-link-media">media</code>"] does not
14283-
<span data-x="matches the environment">match the environment</span>, then
14284-
<span>continue</span>.</p></li>
14285-
14286-
<li><p>Let <var>element</var> be the result of
14287-
<span data-x="create an element">creating an element</span> given <var>document</var>,
14288-
<code>link</code>, and the <span>HTML namespace</span>.</p></li>
14289-
14290-
<li><p><span data-x="map iterate">For each</span> <var>entry</var> in <var>params</var>: If
14291-
<var>entry</var>[0] is "<code data-x="attr-link-as">as</code>",
14292-
"<code data-x="attr-img-srcset">rel</code>", "<code data-x="attr-link-type">type</code>",
14293-
"<code data-x="attr-link-crossorigin">crossorigin</code>",
14294-
"<code data-x="attr-link-imagesizes">imagesizes</code>",
14295-
"<code data-x="attr-link-blocking">blocking</code>",
14296-
"<code data-x="attr-link-rev">rev</code>",
14297-
"<code data-x="attr-link-integrity">integrity</code>",
14298-
"<code data-x="attr-link-imagesrcset">imagesrcset</code>", or
14299-
"<code data-x="attr-link-media">media</code>", then
14300-
<span data-x="concept-element-attributes-set-value">set an attribute value</span> for
14301-
<var>element</var> using <var>entry</var>[0] and <var>entry</var>[1].</p></li>
14302-
14303-
<li><p><span data-x="concept-element-attributes-set-value">Set an attribute value</span> for
14304-
<var>element</var> using "<code data-x="attr-link-href">href</code>" and
14305-
<var>href</var>.</p></li>
14306-
14307-
<li><p><span data-x="fetch and process the linked resource">Fetch and process</span>
14308-
<var>el</var>.</p></li>
14309-
</ol>
14310-
</li>
14311-
</ol>
14312-
14313-
<p class="XXX">The processing of `<code data-x="http-link">Link</code>` headers apart from
14314-
<code data-x="rel-preload">preload</code>, in particular their influence on a
14315-
<code>Document</code>'s <span>script-blocking style sheet counter</span>, is not defined. See
14316-
<a href="https://github.com/whatwg/html/issues/4224">issue #4224</a> for
14317-
discussion on integrating this into the spec.</p>
14318-
14319-
<p>To <dfn>parse a link header</dfn> given a <span>string</span> <var>input<var>, do the
14320-
following, as specified in Web Linking: <ref spec=WEBLINK></p>
14321-
14322-
<ol>
14323-
<li><p>Let <var>position</var> point at the first code point of <var>input</var>.</p></li>
14324-
14325-
<li><p><span>Skip ASCII whitespace</span> within <var>input</var> given
14326-
<var>position</var>.</p></li>
14327-
14328-
<li><p>If <var>input</var>[<var>position</var>] is an U+003C LESS-THAN SIGN (&lt;),
14329-
then advance <var>position</var> by 1; otherwise return null.</p></li>
14330-
14331-
<li><p><span>Skip ASCII whitespace</span> within <var>input</var> given
14332-
<var>position</var>.</p></li>
14333-
14334-
<li><p><span>Collect a sequence of code points</span> that are not an U+003E GREATER-THAN SIGN
14335-
(>) from <var>input</var> given <var>position</var>, and let <var>href</var> be the
14336-
result.</p></li>
14337-
14338-
<li><p>If <var>position</var> is at the end of <var>input, return null; otherwise advance
14339-
<var>position</var> by 1.</p></li>
14253+
<li>
14254+
<p><span data-x="list iterate">For each</span> <var>linkObject</var> of
14255+
<var>linkObjects</var>, run these steps:</p>
1434014256

14341-
<li><p>Let <var>href</var> be the result of <span data-x="strip leading and trailing ASCII
14342-
whitespace">stripping leading and trailing ASCII whitespace</span> <var>href</var>.</p></li>
14257+
<ol>
14258+
<li>
14259+
<p>If <var>linkObject</var>["<code data-x="">relation_type</code>"] is not
14260+
"<code data-x="rel-preload">preload</code>", then <span>continue</span>.</p>
1434314261

14344-
<li><p>If <var>href</var> is an empty string, return null.</p></li>
14262+
<p class=note>Additional support for link types can be added here in the future.</p>
14263+
</li>
1434514264

14346-
<li><p>Advance <var>position</var> to <var>gtSigns</var>[0] + 1.</p></li>
14265+
<li><p>Let <var>attribs</var> be
14266+
<var>linkObject</var>["<code data-x="">target_attributes</code>"].</p></li>
1434714267

14348-
<li><p>Let <var>params</var> be a new <span data-x="ordered map">map</span>.</p></li>
14268+
<li><p>Let <var>expectedPhase</var> be "<code data-x="">media</code>" if either
14269+
"<code data-x="attr-img-srcset">srcset</code>",
14270+
"<code data-x="attr-link-imagesrcset">imagesrcset</code>", or <code
14271+
data-x="attr-link-media">media</code>" <span data-x="map exists">exist</span> in
14272+
<var>attribs</var>; otherwise false.</p></li>
1434914273

14350-
<li>
14351-
<p>While <var>position</var> is not past the end of <var>input</var>:<p>
14352-
14353-
<ol>
14354-
<li><p><span>Skip ASCII whitespace</span> within <var>input</var> given
14355-
<var>position</var>.</p></li>
14356-
14357-
<li><p>If <var>input</var>[<var>position</var>] is an U+003B SEMICOLON (;), then advance
14358-
<var>position</var> by 1; otherwise return null.</p></li>
14274+
<li><p>If <var>expectedPhase</var> is not <var>phase</var>, then
14275+
<span>continue</span>.</p></li>
1435914276

14360-
<li><p><span>Skip ASCII whitespace</span> within <var>input</var> given
14361-
<var>position</var>.</p></li>
14277+
<li><p>If <var>params</var> includes "<code data-x="attr-link-media">media</code>" and
14278+
<var>params</var>["<code data-x="attr-link-media">media</code>"] does not
14279+
<span data-x="matches the environment">match the environment</span>, then
14280+
<span>continue</span>.</p></li>
1436214281

14363-
<li><p>If <var>position</var> is past the end of <var>input</var>, then return null.</p></li>
14282+
<li><p>Let <var>element</var> be the result of
14283+
<span data-x="create an element">creating an element</span> given <var>document</var>,
14284+
<code>link</code>, and the <span>HTML namespace</span>.</p></li>
1436414285

14286+
<li><p><span data-x="concept-element-attributes-set-value">Set an attribute value</span> for
14287+
<var>element</var> using "<code data-x="attr-link-href">href</code>" and
14288+
<var>linkObject</var>["<code data-x="">target_uri</code>"].</p></li>
1436514289

14290+
<li><p><span data-x="concept-element-attributes-set-value">Set an attribute value</span> for
14291+
<var>element</var> using "<code data-x="attr-link-href">rel</code>" and
14292+
<var>linkObject</var>["<code data-x="">relation_type</code>"].</p></li>
14293+
14294+
<li><p><span data-x="map iterate">For each</span> <var>entry</var> in <var>attribs</var>: If
14295+
<var>entry</var>[0] is "<code data-x="attr-link-as">as</code>",
14296+
"<code data-x="attr-link-type">type</code>",
14297+
"<code data-x="attr-link-crossorigin">crossorigin</code>",
14298+
"<code data-x="attr-link-imagesizes">imagesizes</code>",
14299+
"<code data-x="attr-link-blocking">blocking</code>",
14300+
"<code data-x="attr-link-integrity">integrity</code>",
14301+
"<code data-x="attr-link-imagesrcset">imagesrcset</code>", or
14302+
"<code data-x="attr-link-media">media</code>", then
14303+
<span data-x="concept-element-attributes-set-value">set an attribute value</span> for
14304+
<var>element</var> using <var>entry</var>[0] and <var>entry</var>[1].</p></li>
14305+
14306+
<li><p><span data-x="fetch and process the linked resource">Fetch and process</span>
14307+
<var>el</var>.</p></li>
1436614308
</ol>
1436714309
</li>
14368-
14369-
<li><p><span data-x="list iterate">For each</span> token returned by
14370-
<span data-x="strictly split">strictly splitting</span> <var> on the U+003B SEMICOLON character (;)
14371-
14372-
<li><p>Let <var>paramsString</var> be the result of
14373-
<span data-x="strip leading and trailing ASCII
14374-
whitespace">stripping leading and trailing ASCII whitespace</span> from
14375-
the substring of <var>trimmedHeader</var> between <var>gtSigns</var>[0] and
14376-
<var>trimmedHeader</var>'s length.</p></li>
14377-
14378-
<li><p>If <var>paramsString</var>[0] is not U+003B SEMICOLON (;), return null.
14379-
14380-
14381-
14382-
14383-
<li><p>Return (<var>href</var>, <var>params</var>).</p></li>
14384-
1438514310
</ol>
1438614311

14387-
<code>Document</code> <var>doc</var>,
14388-
<span data-x="concept-response">response</span>, and a "<code data-x="">pre-media</code>" or
14389-
"<code data-x="">media</code>" <var>phase</var>:</p>
14390-
14391-
</div>
14312+
<p class="XXX">The processing of `<code data-x="http-link">Link</code>` headers apart from
14313+
<code data-x="rel-preload">preload</code>, in particular their influence on a
14314+
<code>Document</code>'s <span>script-blocking style sheet counter</span>, is not defined. See
14315+
<a href="https://github.com/whatwg/html/issues/4224">issue #4224</a> for
14316+
discussion on integrating this into the spec.</p>
14317+
14318+
</div>
1439214319

1439314320
<h5>Providing users with a means to follow hyperlinks created using the <code>link</code>
1439414321
element</h5>

0 commit comments

Comments
 (0)