Reputation: 1
How can I set my server's HTTP response to:
HTTP/1.1 206 Partial Content
In PHP I would write header('HTTP/1.1 206 Partial Content')
but what about in Perl CGI?
I'm using this code but the client reports an HTTP 500 error
if ( defined $ENV{HTTP_RANGE} ) {
my $startrange = 500;
my $endrange = 900;
$length = $endrange-$startrange;
print qq{HTTP/1.1 206 Partial Content\n};
my $range = $startrange.'-'.$endrange.'/'.$filesize;
print qq{Content-Range: bytes $range\n};
}
print qq{Accept-Ranges: bytes\n};
print qq{Content-Disposition: attachment; filename="$filename"\n};
print qq{Content-length: $length\n\n};
I have checked the error log, which says this:
malformed header from script 'download.cgi': Bad header: HTTP/1.1 206 Partial Content
Upvotes: 0
Views: 690
Reputation: 2466
You should not send a HTTP status line for Partial Content response in a CGI script. Your script should send a correct CGI response:
1*header-field NL [ response-body ]
This should work:
Status: 206 Partial Content\n
Content-Range: bytes 500-900/12000\n
Content-Type: ?\n
Your script must also send a Content-Type header:
If an entity body is returned, the script MUST supply a Content-Type field in the response.
Upvotes: 2