File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,30 @@ You can also add links to the HTTP response directly from controllers and servic
195
195
}
196
196
}
197
197
198
+ Parsing Link Headers
199
+ --------------------
200
+
201
+ Some third-party APIs provide resources such as pagination URLs using the
202
+ ``Link `` HTTP header. The WebLink component provides the
203
+ :class: `Symfony\C omponent\W ebLink\H ttpHeaderParser ` utility class to parse
204
+ those headers and transform them into :class: `Symfony\C omponent\W ebLink\L ink `
205
+ instances::
206
+
207
+ use Symfony\Component\WebLink\HttpHeaderParser;
208
+
209
+ $parser = new HttpHeaderParser();
210
+ // get the value of the Link header from the Request
211
+ $linkHeader = '</foo.css>; rel="prerender",</bar.otf>; rel="dns-prefetch"; pr="0.7",</baz.js>; rel="preload"; as="script"';
212
+
213
+ $links = $parser->parse($linkHeader)->getLinks();
214
+ $links[0]->getRels(); // ['prerender']
215
+ $links[1]->getAttributes(); // ['pr' => '0.7']
216
+ $links[2]->getHref(); // '/baz.js'
217
+
218
+ .. versionadded :: 7.4
219
+
220
+ The ``HttpHeaderParser `` class was introduced in Symfony 7.4.
221
+
198
222
.. _`WebLink` : https://github.com/symfony/web-link
199
223
.. _`HTTP/2 Server Push` : https://tools.ietf.org/html/rfc7540#section-8.2
200
224
.. _`Resource Hints` : https://www.w3.org/TR/resource-hints/
You can’t perform that action at this time.
0 commit comments