0

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
5
  • 1
    You can't get an HTTP 500 error on the server. You have given way too little information. Show your code and describe the network Commented Jun 5, 2016 at 18:59
  • @Borodin i have just updated the question, check the code, .. for some reason i'm getting HTTP 500 error but if i remove that line print qq{HTTP/1.1 206 Partial Content\n}; i get 200 OK, i need to get 206 Partial Content for resumable download Commented Jun 5, 2016 at 19:06
  • @Borodin nevermind i have just selected the best answer :) Commented Jun 5, 2016 at 20:36
  • 1
    @Borodin, You are incorrect! CGI responses differs from HTTP responses! But what do I know about HTTP or CGI? I have only written most Engines for Catalyst, HTTP::Body, HTTP::Tiny and maintains FCGI ;o) Commented Jun 5, 2016 at 20:58
  • @chansen: Yes, my senses departed me and I made a mistake. Your reminder that this is CGI and not bare HTTP restored them. Thank you Commented Jun 5, 2016 at 21:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

That what i was looking for. Thank you ^^
@Borodin, CGI responses differs from HTTP responses! First and second hyperlink refers to the HTTP standard, third and forth hyperlinks refers to the CGI standard.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.