I have a problem with a HTTP::Response Perl object from a remote server that sometimes returns the HTTP response with duplicated 'Content-Length' headers.
When this occurs, if the content-length value is '43215', when I read the header value with:
print ($response->header('Content-length'));
the result is:
4321543215
How can I detect if the header is duplicated and access to the real value?
From the fine manual for HTTP::Headers
:
A multi-valued field will be returned as separate values in list context and will be concatenated with "," as separator in scalar context.
and this is list context:
print ($response->header('Content-length'))
So, $response->header()
is returning both Content-length
headers as a list and the result is, essentially:
print join('', 43215, 43215)
You can either use kork's $response->content_length()
approach or grab all the Content-length
headers in an array and use the first one as the length:
my @lengths = $response->header('Content-length');
my $length = $lengths[0];
If you end up getting multiple Content-length
headers and they're different then someone is very confused.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With