Am 10/10/2022 um 13:40 schrieb Daniel Tschlatscher:
> It does save about 20 lines of very redundant code in both pmg and pve
> each and should make it easy to implement potential other download
> calls. Though, that hinges on the question on how likely it is that
> there will be such a need.


20 lines is:
1) really not _that_ much
2) especially not dramatic as its just plain boilerplate info that won't
   change
3) only your version needs that much ;-P Can be easily cut down of 16 lines

    my $fh;
    if ($compress) {
        open($fh, '-|', "/usr/bin/gzip", "-c", "$file") or die "could not open 
file $file - $!";
    } else {
        open($fh, '<', $file) or die "could not open file $file- $!";
    }

    return {
        download => {
            fh => $fh,
            stream => 1,
            'content-encoding' => $compress ? 'gzip' : undef,
            'content-type' => $content_type // 'text/plain',
            'content-disposition' => 'attachment; filename="'. ($suggested_name 
// $file) .'"',
        },
    };



And independent of that, pve-common would be the wrong place for that helper, 
as it has no
control over how the http server takes the streaming hint, i.e., this is not a 
general
stream middleware but only prepare it in the specific format that our perl http 
server
expects it. So _iff_ it should go into pve-http-server, as otherwise any 
changes would need
and extra level of coordination on upgrade and possibly even make pve-common 
depend on
pve-http-server, introducing a circular dependency.



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to