Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
FetchOptions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\ResourceLoader;
6
7/**
8 * Per-fetch policy: timeout, redirect chain length, max payload size,
9 * extra headers, override user-agent.
10 *
11 * Immutable; instantiate once and pass to {@see ResourceLoader::fetch}.
12 * Sensible defaults are tuned for the most common case (embedding a
13 * remote image in a PDF) — bump `maxContentLengthBytes` if you
14 * expect large fonts or hi-res images.
15 */
16final readonly class FetchOptions
17{
18    /**
19     * @param int                     $timeoutSeconds          Hard
20     *                                                          ceiling
21     *                                                          on the
22     *                                                          whole
23     *                                                          fetch
24     *                                                          (connect
25     *                                                          + read).
26     * @param int                     $maxRedirects            Stop
27     *                                                          following
28     *                                                          redirects
29     *                                                          past
30     *                                                          this
31     *                                                          depth.
32     * @param int                     $maxContentLengthBytes   Reject
33     *                                                          responses
34     *                                                          declaring
35     *                                                          or
36     *                                                          streaming
37     *                                                          more
38     *                                                          than
39     *                                                          this
40     *                                                          number
41     *                                                          of bytes.
42     *                                                          50 MB
43     *                                                          default
44     *                                                          covers
45     *                                                          large
46     *                                                          PNG /
47     *                                                          font
48     *                                                          files
49     *                                                          without
50     *                                                          exposing
51     *                                                          the
52     *                                                          host
53     *                                                          to
54     *                                                          memory
55     *                                                          exhaustion.
56     * @param string                  $userAgent               Sent as
57     *                                                          `User-Agent:`.
58     * @param array<string, string>   $headers                 Extra
59     *                                                          request
60     *                                                          headers
61     *                                                          (e.g.
62     *                                                          `Accept`,
63     *                                                          `Accept-Language`).
64     *                                                          Authorization
65     *                                                          headers
66     *                                                          should
67     *                                                          NOT
68     *                                                          be set
69     *                                                          here —
70     *                                                          the
71     *                                                          loader
72     *                                                          strips
73     *                                                          them
74     *                                                          across
75     *                                                          redirects
76     *                                                          per
77     *                                                          RFC 9110
78     *                                                          §15.4.
79     */
80    public function __construct(
81        public int $timeoutSeconds = 10,
82        public int $maxRedirects = 5,
83        public int $maxContentLengthBytes = 50_000_000,
84        public string $userAgent = 'phpdftk-resource-loader/1.0',
85        public array $headers = [],
86    ) {}
87}