UA can't upload a Mojo::Asset::File having start_range & end_range
- Mojolicious version: 9.22
- Perl version: v5.34
- Operating system: Ubuntu Linux 20.04
Steps to reproduce the behavior
Attempts to upload part of a file with Mojo::UserAgent, using Mojo::Asset::File and the asset's start_range/end_range properties fail after a long pause.
use Data::Dumper;
my $asset = Mojo::Asset::File->new(
path => 'file.txt',
start_range => 100,
end_range => 105,
);
my $ua = Mojo::UserAgent->new;
my $tx = $ua->post('http://localhost:3000/upload_file', form => {
up => { file => $asset },
});
print Dumper($tx->error);
Expected behavior
I expected those 6 bytes to be uploaded quickly and no error to occur.
Actual behavior
After 60 seconds I got this error:
$VAR1 = {
'error' => {
'message' => 'Premature connection close'
}
};
Mojo::Asset::File->size() only ever returns the size of the whole asset so the multipart message has the wrong content length, hence the premature connection close as the server waits for more content. It can be done with a subset of the asset by creating a new one to pass in the form {file => Mojo::Asset::File->new->add_chunk($asset->get_chunk($start, $end))}
That seems like a bug.