shivams
shivams

Reputation: 2717

How to send back custom HTTP headers from my Perl server?

I am writing a Perl HTTP server using HTTP::Daemon. My Perl client is sending a HEAD request to the server to get the content length of the file which IO have to GET later.

My problem is that I am not able to generate a custom header and send it back to the client.

I can send back basic HTTP headers using $c->send_basic_header, but as soon as I try to send specific headers using $c->send_header( $field1, $value1, $field2, $value2, ... ) it does not work.

I am not able to understand what is the problem.

The headers which I am trying to send is

$c->send_header('Content-Type','image/jpeg','Cotent-Length','56360','Accept-Ranges','bytes')

I am new to Perl, so please help me understand how to do this.

Upvotes: 1

Views: 581

Answers (1)

Borodin
Borodin

Reputation: 126722

You don't show your code, but do you realise that you need to send_basic_header as well as send_header?

Your code should look like this

$c->send_basic_header;
$c->send_header(
    'Content-Type'   => 'image/jpeg',
    'Content-Length' => '56360',
    'Accept-Ranges'  => 'bytes',
);
$c->send_crlf;

Upvotes: 1

Related Questions