sherver icon indicating copy to clipboard operation
sherver copied to clipboard

Transfer-Encoding: chunked util.

Open adedomin opened this issue 4 years ago • 1 comments

I noticed your server appears to respond with HTTP/1.0 which is a bit rickety. If you aren't sure of the output length of your responses, you could always uses chunked encoding. When I did shell-based CGI for one-off stuff I use to use a perl script to wrap or transfer giant unknown-sized junk all the time.

I don't really feel like making a PR for it, but I'll inline it here:

#!/usr/bin/perl
use strict;

# print piped text or a list of files
# using HTTP Transfer-Encoding: chunked

sub http_chunk {
    my $fh = $_[0];
    my $buf;
    my $last_size;
    while (($last_size = read($fh, $buf, 131072)) gt 0) {
        printf("%x\r\n%s\r\n", $last_size, $buf);
    }
}

if (scalar(@ARGV) gt 0) {
    for my $f (@ARGV) {
        my $fh;
        open($fh, "<", $f);
        binmode($fh);
        http_chunk($fh);
    }
}
else {
    binmode(STDIN);
    http_chunk(*STDIN);
}
printf("0\r\n\r\n");

adedomin avatar Dec 22 '21 12:12 adedomin

Do you use this on serverside or client side or both? Im building a lightweight NextCloud alternative using sherver as the backend. It needs to be able to chunk data and reassemble.

DethByte64 avatar Dec 03 '24 20:12 DethByte64