###PERL;
# proxy.pl is generated from proxy.1.pl
###PERL;
# proxy.pl is generated from proxy.1.pl
#
# This is the proxy software. It's launched as a CGI program by the http server.
#
#
# This is the proxy software. It's launched as a CGI program by the http server.
#
my $lastskipped=1; # if the previous header field was not forwarded
my $forceexit=0; # if the proxy should exit with error
my $errormsg;
my $lastskipped=1; # if the previous header field was not forwarded
my $forceexit=0; # if the proxy should exit with error
my $errormsg;
+ my $rangestart; # first byte of partial content
+ my $rangelength; # total length when partial content
$contentlength = int($headval);
}
$contentlength = int($headval);
}
+ # Only part of the content is transmitted in this request
+ if(($status =~ /^206/)&&($headname eq 'content-range')) {
+ if (lc($headval) =~ /^[\r\n \t]*bytes ([0-9]+)\-[0-9]\/([0-9]*)/) {
+ $rangestart = int($1);
+ $rangelength = int($2);
+ }
+ }
+
# Some header fields should not be forwarded.
if($headname =~ RESPONSE_HEADER_BLOCK) {
$lastskipped =1;
# Some header fields should not be forwarded.
if($headname =~ RESPONSE_HEADER_BLOCK) {
$lastskipped =1;
# Only add the Content-length header if it's safe to do so.
if ($definedlength and ($safelength or ($contentlength==0))) {
# Only add the Content-length header if it's safe to do so.
if ($definedlength and ($safelength or ($contentlength==0))) {
- push @resphead, 'Content-length: '.$contentlength;
+ push @resphead, 'Content-length: '.(($rangelength ne '')?$rangelength:$contentlength);
}
# After forwarding the response header it's too late to send any error
}
# After forwarding the response header it's too late to send any error
# Forward the header and safe it to file if possible and allowed.
if ($archive) {
# Forward the header and safe it to file if possible and allowed.
if ($archive) {
- $respheadopen = open($respheadfile, ">", $respheadpath);
+ if($rangestart ne '') {
+ $respheadopen = open($respheadfile, ">>", $respheadpath);
+ }
+ else{
+ $respheadopen = open($respheadfile, ">", $respheadpath);
+ }
}
foreach $line (@resphead) {
print $line."\n";
}
foreach $line (@resphead) {
print $line."\n";
}
if ($firstline) {
if ($archive) {
}
if ($firstline) {
if ($archive) {
- $respcontopen = open($respcontfile, ">", $respcontpath);
+ if($rangestart ne '') {
+ if(-f $respcontpath) {
+ $respcontopen = open($respcontfile, "+<", $respcontpath);
+ }
+ else {
+ $respcontopen = open($respcontfile, ">", $respcontpath);
+ }
+ }
+ else {
+ $respcontopen = open($respcontfile, ">", $respcontpath);
+ }
}
if ($respcontopen){
unless (binmode($respcontfile)) {
close($respcontfile);
$respcontopen=0;
}
}
if ($respcontopen){
unless (binmode($respcontfile)) {
close($respcontfile);
$respcontopen=0;
}
+ else {
+ if($rangestart ne '') {
+ seek($respcontfile,0,$rangestart);
+ }
+ }
+ if($rangelength ne '') {
+ truncate($respcontfile,$rangelength);
+ }
close ($respcontfile);
}
}
close ($respcontfile);
}
}