Server/MirrorFetcher/HTTP.pm

filter: Statementstmt 95.8% 138 / 144 Branchbran 82.5% 66 / 80 Conditioncond 63.1% 36 / 57 MC/DCmcdc 37.9% 11 / 29 Subroutinesub 100% 19 / 19 Podpod 100% 4 / 4 totaltotal 82.2% 274 / 333 CC 61 SCAR 23.0
CC
61
Cov
85%
BUILD
18.2
_validated_url
14.8
fetch_blob
13.1
CRAP 10.0
« Server/Storage.pm ↑ Summary Server/Request.pm »
1 package Net::Blossom::Server::MirrorFetcher::HTTP;
2  
3 2 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶use Net::Blossom::_ConstructorArgs ();
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Net::Blossom::Server::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Class::Tiny qw(_allowed_hosts max_bytes user_agent), {
Subroutine BEGIN: called CC=1 SCAR=0.0
10 timeout => 5,
11 2 };
12 2 ▶use HTTP::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use URI ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 my $DEFAULT_TIMEOUT = 5;
17  
18 20 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=9 SCAR=22.1
Pod documented
19 20 my $class = shift;
20 20 my %args = Net::Blossom::_ConstructorArgs::normalize(@_);
21 20 my %known = map { $_ => 1 } qw(allowed_hosts timeout max_bytes user_agent);
22 20 my @unknown = grep { !exists $known{$_} } keys %args;
23 20 ▶ croak "unknown argument(s): " . join(', ', sort @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 19 20
24  
25 19 ▶ croak "allowed_hosts is required" unless defined $args{allowed_hosts};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"allowed_hosts"} 1 18 19
26 18 ▶ croak "allowed_hosts must be an array reference" unless ref($args{allowed_hosts}) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"allowed_hosts"} eq "ARRAY" 0 18 18
27 18 ▶ croak "allowed_hosts must not be empty" unless @{$args{allowed_hosts}};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$args{"allowed_hosts"};} 1 17 18
28 17 my @allowed_hosts;
29 17 for my $host (@{$args{allowed_hosts}}) {
30 18 ▶ croak "allowed_hosts must contain host names only"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host and not ref $host and _valid_allowed_host($host) 1 17 18
Condition50%3/6
defined $host and not ref $host and _valid_allowed_host($host)
!ll&&!rl&&r
0117
defined $host and not ref $host
!ll&&!rl&&r
0018
MC/DC33%1/3
defined $host and not ref $host and _valid_allowed_host($host)
defined $host not ref $host _valid_allowed_host($host)
Truth table50%2/4
A and not(B) and C
A= defined $hostB= not ref $hostC= _valid_allowed_host($host)
ABCresult
0XX0
10X0
1100
1111
31 unless defined $host && !ref($host) && _valid_allowed_host($host);
32 17 push @allowed_hosts, lc $host;
33 }
34 16 $args{_allowed_hosts} = \@allowed_hosts;
35 16 delete $args{allowed_hosts};
36  
37 16 return \%args;
38 }
39  
40 16 ▶sub BUILD {
Subroutine BUILD: called CC=12 SCAR=29.0
Pod documented
41 16 my ($self) = @_;
42 16 ▶ croak "max_bytes is required" unless defined $self->max_bytes;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->max_bytes 1 15 16
43 15 ▶ croak "max_bytes must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $self->max_bytes and $self->max_bytes =~ /\A[1-9][0-9]*\z/ 1 14 15
Condition66%2/3
not ref $self->max_bytes and $self->max_bytes =~ /\A[1-9][0-9]*\z/
!ll&&!rl&&r
0114
MC/DC50%1/2
not ref $self->max_bytes and $self->max_bytes =~ /\A[1-9][0-9]*\z/
not ref $self->max_bytes $self->max_bytes =~ /\A[1-9][0-9]*\z/
Truth table66%2/3
not(A) and B
A= not ref $self->max_bytesB= $self->max_bytes =~ /\A[1-9][0-9]*\z/
ABresult
0X0
100
111
44 unless !ref($self->max_bytes) && $self->max_bytes =~ /\A[1-9][0-9]*\z/;
45  
46 14 ▶ $self->timeout($DEFAULT_TIMEOUT) unless defined $self->timeout;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->timeout 0 14 14
47 14 ▶ croak "timeout must be a positive integer"
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $self->timeout and $self->timeout =~ /\A[1-9][0-9]*\z/ 1 13 14
Condition66%2/3
not ref $self->timeout and $self->timeout =~ /\A[1-9][0-9]*\z/
!ll&&!rl&&r
0113
MC/DC50%1/2
not ref $self->timeout and $self->timeout =~ /\A[1-9][0-9]*\z/
not ref $self->timeout $self->timeout =~ /\A[1-9][0-9]*\z/
Truth table66%2/3
not(A) and B
A= not ref $self->timeoutB= $self->timeout =~ /\A[1-9][0-9]*\z/
ABresult
0X0
100
111
48 unless !ref($self->timeout) && $self->timeout =~ /\A[1-9][0-9]*\z/;
49  
50 13 ▶ if (defined $self->user_agent) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->user_agent) { } 13 0 13
51 13 ▶ croak "user_agent must provide request"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->user_agent) and $self->user_agent->can("request") 1 12 13
Condition66%2/3
builtin::blessed($self->user_agent) and $self->user_agent->can("request")
!ll&&!rl&&r
0112
MC/DC50%1/2
builtin::blessed($self->user_agent) and $self->user_agent->can("request")
builtin::blessed($self->user_agent) $self->user_agent->can("request")
Truth table66%2/3
A and B
A= builtin::blessed($self->user_agent)B= $self->user_agent->can("request")
ABresult
0X0
100
111
52 unless blessed($self->user_agent) && $self->user_agent->can('request');
53 }
54 else {
55 0 my %http_args = (
56 agent => 'Net-Blossom-Server',
57 timeout => $self->timeout,
58 max_redirect => 0,
59 max_size => $self->max_bytes,
60 proxy => undef,
61 );
62 0 ▶ $http_args{http_proxy} = undef if HTTP::Tiny->can('http_proxy');
Branch: 1 branch
BranchTrueFalseTotal
if "HTTP::Tiny"->can("http_proxy") 0 0 0
63 0 ▶ $http_args{https_proxy} = undef if HTTP::Tiny->can('https_proxy');
Branch: 1 branch
BranchTrueFalseTotal
if "HTTP::Tiny"->can("https_proxy") 0 0 0
64 0 $self->user_agent(HTTP::Tiny->new(%http_args));
65 }
66  
67 12 return;
68 }
69  
70 3 ▶sub allowed_hosts {
Subroutine allowed_hosts: called CC=1 SCAR=0.0
Pod documented
71 3 my ($self) = @_;
72 3 return [@{$self->_allowed_hosts}];
73 }
74  
75 20 ▶sub fetch_blob {
Subroutine fetch_blob: called CC=13 SCAR=25.7
Pod documented
76 20 my $self = shift;
77 20 my ($url, %opts) = @_;
78 20 my %known = map { $_ => 1 } qw(sink);
79 20 my @unknown = grep { !exists $known{$_} } keys %opts;
80 20 ▶ croak "unknown option(s): " . join(', ', sort @unknown) if @unknown;
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 0 20 20
81 20 ▶ croak "sink is required" unless defined $opts{sink};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts{"sink"} 1 19 20
82 croak "sink must provide start and write"
83 19 ▶ unless blessed($opts{sink}) && $opts{sink}->can('start') && $opts{sink}->can('write');
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($opts{"sink"}) and $opts{"sink"}->can("start") and $opts{"sink"}->can("write") 1 18 19
Condition66%4/6
builtin::blessed($opts{"sink"}) and $opts{"sink"}->can("start") and $opts{"sink"}->can("write")
!ll&&!rl&&r
1018
builtin::blessed($opts{"sink"}) and $opts{"sink"}->can("start")
!ll&&!rl&&r
0118
MC/DC33%1/3
builtin::blessed($opts{"sink"}) and $opts{"sink"}->can("start") and $opts{"sink"}->can("write")
builtin::blessed($opts{"sink"}) $opts{"sink"}->can("start") $opts{"sink"}->can("write")
Truth table50%2/4
A and B and C
A= builtin::blessed($opts{"sink"})B= $opts{"sink"}->can("start")C= $opts{"sink"}->can("write")
ABCresult
0XX0
10X0
1100
1111
84  
85 18 my $uri = _validated_url($url);
86 15 my $host = lc $uri->host;
87  
88 15 my %allowed = map { $_ => 1 } @{$self->_allowed_hosts};
89 Net::Blossom::Server::Error->throw(
90 status => 403,
91 reason => 'Mirror URL host is not allowed',
92 15 ▶ ) unless $allowed{$host};
Branch: 1 branch
BranchTrueFalseTotal
unless $allowed{$host} 1 14 15
93  
94 # The allowlist names hosts only, so an allowed host must not be usable to
95 # reach an arbitrary port (e.g. internal services co-located on that host).
96 14 ▶ Net::Blossom::Server::Error->throw(
Branch: 1 branch
BranchTrueFalseTotal
if $uri->port != $uri->default_port 2 12 14
97 status => 403,
98 reason => 'Mirror URL port is not allowed',
99 ) if $uri->port != $uri->default_port;
100  
101 12 my $started = 0;
102 12 my $size = 0;
103 12 my %metadata;
104 my $sink_error;
105 12 my $response = eval {
106 12 local @ENV{qw(http_proxy HTTP_PROXY https_proxy HTTPS_PROXY all_proxy ALL_PROXY no_proxy NO_PROXY)};
107 12 delete @ENV{qw(http_proxy HTTP_PROXY https_proxy HTTPS_PROXY all_proxy ALL_PROXY no_proxy NO_PROXY)};
108  
109 $self->user_agent->request('GET', $url, {
110 11 ▶ data_callback => sub {
Subroutine __ANON__: called CC=6 SCAR=18.1
111 11 my ($chunk, $response) = @_;
112 11 ▶ croak "response chunks must be scalars" if ref($chunk);
Branch: 1 branch
BranchTrueFalseTotal
if ref $chunk 0 11 11
113  
114 11 _ensure_successful_response($response);
115 10 ▶ if (!$started) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($started) 9 1 10
116 9 %metadata = _metadata_from_response($response, $self->max_bytes);
117 7 ▶ eval { $opts{sink}->start(%metadata); 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $opts{"sink"}->start(%metadata); 1 } } or do { $sink_error = $@; die $sink_error } 7 0 7
118 0 $sink_error = $@;
119 0 die $sink_error;
120 };
121 7 $started = 1;
122 }
123  
124 8 my $new_size = $size + length($chunk);
125 8 ▶ _too_large() if $new_size > $self->max_bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $new_size > $self->max_bytes 1 7 8
126 7 ▶ eval { $opts{sink}->write($chunk); 1 } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $opts{"sink"}->write($chunk); 1 } } or do { $sink_error = $@; die $sink_error } 6 1 7
127 1 $sink_error = $@;
128 1 die $sink_error;
129 };
130 6 $size = $new_size;
131 },
132 12 });
133 };
134 12 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 6 6 12
135 6 ▶ die $sink_error if defined $sink_error;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sink_error 1 5 6
136 5 ▶ die $@ if blessed($@) && $@->isa('Net::Blossom::Server::Error');
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($@) and $@->isa("Net::Blossom::Server::Error") 4 1 5
Condition66%2/3
builtin::blessed($@) and $@->isa("Net::Blossom::Server::Error")
!ll&&!rl&&r
104
MC/DC50%1/2
builtin::blessed($@) and $@->isa("Net::Blossom::Server::Error")
builtin::blessed($@) $@->isa("Net::Blossom::Server::Error")
Truth table66%2/3
A and B
A= builtin::blessed($@)B= $@->isa("Net::Blossom::Server::Error")
ABresult
0X0
100
111
137 1 Net::Blossom::Server::Error->throw(
138 status => 502,
139 reason => 'Origin fetch failed',
140 );
141 }
142  
143 6 _ensure_successful_response($response);
144  
145 6 ▶ if (!$started) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($started) 1 5 6
146 1 %metadata = _metadata_from_response($response, $self->max_bytes);
147 1 $opts{sink}->start(%metadata);
148 }
149 6 return \%metadata;
150 }
151  
152 18 ▶sub _validated_url {
Subroutine _validated_url: called CC=12 SCAR=26.9
153 18 my ($url) = @_;
154 18 ▶ Net::Blossom::Server::Error->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $url and not ref $url and length $url and not $url =~ /[\x00-\x20]/ 0 18 18
Condition33%3/9
defined $url and not ref $url and length $url and not $url =~ /[\x00-\x20]/
!ll&&!rl&&r
0018
defined $url and not ref $url and length $url
!ll&&!rl&&r
0018
defined $url and not ref $url
!ll&&!rl&&r
0018
MC/DC0%0/4
defined $url and not ref $url and length $url and not $url =~ /[\x00-\x20]/
defined $url not ref $url length $url not $url =~ /[\x00-\x20]/
Truth table20%1/5
A and not(B) and C and not(D)
A= defined $urlB= not ref $urlC= length $urlD= not $url =~ /[\x00-\x20]/
ABCDresult
0XXX0
10XX0
110X0
11100
11111
155 status => 400,
156 reason => 'Invalid mirror URL',
157 ) unless defined $url && !ref($url) && length $url && $url !~ /[\x00-\x20]/;
158  
159 18 my $uri = URI->new($url);
160 18 my $scheme = $uri->scheme;
161 18 my $host = eval { $uri->host };
162 18 my $userinfo = eval { $uri->userinfo };
163  
164 18 ▶ Net::Blossom::Server::Error->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scheme and $scheme =~ /\Ahttps?\z/i and defined $host and length $host and not defined $userinfo && length $userinfo and not defined $uri->fragment 3 15 18
Condition77%14/18
defined $scheme and $scheme =~ /\Ahttps?\z/i and defined $host and length $host and not defined $userinfo && length $userinfo and not defined $uri->fragment
!ll&&!rl&&r
2115
defined $scheme and $scheme =~ /\Ahttps?\z/i and defined $host and length $host and not defined $userinfo && length $userinfo
!ll&&!rl&&r
1116
defined $scheme and $scheme =~ /\Ahttps?\z/i and defined $host and length $host
!ll&&!rl&&r
1017
defined $scheme and $scheme =~ /\Ahttps?\z/i and defined $host
!ll&&!rl&&r
1017
defined $scheme and $scheme =~ /\Ahttps?\z/i
!ll&&!rl&&r
0117
defined $userinfo && length $userinfo
!ll&&!rl&&r
1601
MC/DC42%3/7
defined $scheme and $scheme =~ /\Ahttps?\z/i and defined $host and length $host and not defined $userinfo && length $userinfo and not defined $uri->fragment
defined $scheme $scheme =~ /\Ahttps?\z/i defined $host length $host defined $userinfo length $userinfo not defined $uri->fragment
Truth table44%4/9
A and B and C and D and not(E && F) and not(G)
A= defined $schemeB= $scheme =~ /\Ahttps?\z/iC= defined $hostD= length $hostE= defined $userinfoF= length $userinfoG= not defined $uri->fragment
ABCDEFGresult
0XXXXXX0
10XXXXX0
110XXXX0
1110XXX0
111111X0
11110X00
11111000
11110X11
11111011
165 status => 400,
166 reason => 'Invalid mirror URL',
167 ) unless defined $scheme && $scheme =~ /\Ahttps?\z/i
168 && defined $host && length $host
169 && (!defined($userinfo) || !length($userinfo))
170 && !defined($uri->fragment);
171  
172 15 return $uri;
173 }
174  
175 18 ▶sub _header {
Subroutine _header: called CC=3 SCAR=11.0
176 18 my ($headers, $name) = @_;
177 18 my $value = $headers->{$name};
178 18 ▶ $value = $headers->{lc $name} unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 5 13 18
179 18 ▶ $value = $value->[0] if ref($value) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 0 18 18
180 18 return $value;
181 }
182  
183 17 ▶sub _ensure_successful_response {
Subroutine _ensure_successful_response: called CC=3 SCAR=11.1
184 17 my ($response) = @_;
185 Net::Blossom::Server::Error->throw(
186 status => 502,
187 reason => 'Origin response was not successful',
188 17 ▶ ) unless ref($response) eq 'HASH' && $response->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response eq "HASH" and $response->{"success"} 1 16 17
Condition66%2/3
ref $response eq "HASH" and $response->{"success"}
!ll&&!rl&&r
0116
MC/DC50%1/2
ref $response eq "HASH" and $response->{"success"}
ref $response eq "HASH" $response->{"success"}
Truth table66%2/3
A and B
A= ref $response eq "HASH"B= $response->{"success"}
ABresult
0X0
100
111
189 }
190  
191 10 ▶sub _metadata_from_response {
Subroutine _metadata_from_response: called CC=8 SCAR=20.8
192 10 my ($response, $max_bytes) = @_;
193 10 ▶ my $headers = ref($response->{headers}) eq 'HASH' ? $response->{headers} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $response->{'headers'} eq 'HASH' ? : 10 0 10
194 10 my $content_length = _header($headers, 'content-length');
195 10 ▶ if (defined $content_length) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content_length) 7 3 10
196 7 ▶ Net::Blossom::Server::Error->throw(
Branch: 1 branch
BranchTrueFalseTotal
unless $content_length =~ /\A\d+\z/ 1 6 7
197 status => 502,
198 reason => 'Origin Content-Length is invalid',
199 ) unless $content_length =~ /\A\d+\z/;
200 6 ▶ _too_large() if $content_length > $max_bytes;
Branch: 1 branch
BranchTrueFalseTotal
if $content_length > $max_bytes 1 5 6
201 }
202  
203 8 my $type = _header($headers, 'content-type');
204 8 ▶ $type = 'application/octet-stream' unless defined $type && length $type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and length $type 2 6 8
Condition66%2/3
defined $type and length $type
!ll&&!rl&&r
206
MC/DC50%1/2
defined $type and length $type
defined $type length $type
Truth table66%2/3
A and B
A= defined $typeB= length $type
ABresult
0X0
100
111
205  
206 8 my %metadata = (type => $type);
207 8 ▶ $metadata{content_length} = $content_length if defined $content_length;
Branch: 1 branch
BranchTrueFalseTotal
if defined $content_length 5 3 8
208 8 return %metadata;
209 }
210  
211 2 ▶sub _too_large {
Subroutine _too_large: called CC=1 SCAR=0.0
212 2 Net::Blossom::Server::Error->throw(
213 status => 413,
214 reason => 'Mirrored blob is too large',
215 );
216 }
217  
218 18 ▶sub _valid_allowed_host {
Subroutine _valid_allowed_host: called CC=3 SCAR=11.0
219 18 my ($host) = @_;
220 18 ▶ return 0 if $host =~ /[\x00-\x20]/;
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ /[\x00-\x20]/ 0 18 18
221 18 ▶ return 0 if $host =~ m{[/?#\@:]};
Branch: 1 branch
BranchTrueFalseTotal
if $host =~ m[[/?#\@:]] 1 17 18
222 17 return length $host;
223 }
224  
225 2 1;
226  
227 =pod
228  
229 =head1 NAME
230  
231 Net::Blossom::Server::MirrorFetcher::HTTP - Allowlist HTTP fetcher for Blossom mirrors
232  
233 =head1 SYNOPSIS
234  
235 use Net::Blossom::Server::MirrorFetcher::HTTP;
236  
237 my $fetcher = Net::Blossom::Server::MirrorFetcher::HTTP->new(
238 allowed_hosts => ['cdn.example.com'],
239 max_bytes => 50_000_000,
240 timeout => 5,
241 );
242  
243 my $server = Net::Blossom::Server->new(
244 storage => $storage,
245 mirror_fetcher => $fetcher,
246 );
247  
248 =head1 DESCRIPTION
249  
250 C<Net::Blossom::Server::MirrorFetcher::HTTP> is a small allowlist-only fetcher
251 for C<PUT /mirror>. It is intentionally conservative: it does not provide public
252 internet mirroring by default.
253  
254 The fetcher validates the URL before making a request, requires the URL host to
255 match one of the configured C<allowed_hosts>, disables redirects in the default
256 HTTP client, clears common proxy environment variables while fetching, and
257 enforces a maximum response size while streaming into the supplied sink.
258  
259 =head1 CONSTRUCTOR
260  
261 =head2 new
262  
263 my $fetcher = Net::Blossom::Server::MirrorFetcher::HTTP->new(%args);
264  
265 Required arguments:
266  
267 =over 4
268  
269 =item * C<allowed_hosts>
270  
271 Array reference of host names that may be mirrored. Matching is exact and
272 case-insensitive. Wildcards are not supported. Only default ports for the URL
273 scheme are allowed.
274  
275 =item * C<max_bytes>
276  
277 Positive integer maximum response size in bytes.
278  
279 =back
280  
281 Optional arguments:
282  
283 =over 4
284  
285 =item * C<timeout>
286  
287 Positive integer request timeout in seconds. Defaults to C<5>.
288  
289 =item * C<user_agent>
290  
291 Object with a C<request> method compatible with C<HTTP::Tiny>. This is mainly
292 for tests or applications that need to supply their own HTTP transport.
293  
294 Custom user agents are trusted transport policy. They must not follow redirects
295 unless each redirected URL is checked against the same allowlist, and they must
296 not route requests through proxies or other transports that bypass the configured
297 C<allowed_hosts> policy.
298  
299 =back
300  
301 Unknown arguments or invalid values croak.
302  
303 =head1 ACCESSORS
304  
305 =head2 allowed_hosts
306  
307 Returns a copy array reference of allowed host names.
308  
309 =head2 timeout
310  
311 Returns the request timeout.
312  
313 =head2 max_bytes
314  
315 Returns the maximum response size.
316  
317 =head2 user_agent
318  
319 Returns the HTTP transport object.
320  
321 =head1 METHODS
322  
323 =head2 fetch_blob
324  
325 my $metadata = $fetcher->fetch_blob($url, sink => $sink);
326  
327 Fetches an allowed C<http> or C<https> URL, calls
328 C<< $sink->start(%metadata) >>, streams scalar byte chunks through
329 C<< $sink->write($chunk) >>, and returns a metadata hash reference with C<type>
330 and optional C<content_length>. Missing C<Content-Type> defaults to
331 C<application/octet-stream>. A C<body> value is never returned.
332  
333 The method throws L<Net::Blossom::Server::Error> for expected HTTP-facing
334 failures: C<400> for malformed URLs, C<403> for non-allowlisted hosts, C<413>
335 for blobs larger than C<max_bytes>, and C<502> for origin failures or unusable
336 origin responses.
337  
338 =head1 INTERNAL METHODS
339  
340 =head2 BUILDARGS
341  
342 Normalizes constructor arguments for Class::Tiny.
343  
344 =head2 BUILD
345  
346 Validates the constructed object for Class::Tiny.
347  
348 =cut
« Server/Storage.pm ↑ Summary Server/Request.pm »