Subject: | HTTP PUT and HTTP Post do not work with value 0 (zero) |
Date: | Thu, 27 Nov 2014 12:57:10 +0100 (CET) |
To: | bug-REST-Client [...] rt.cpan.org |
From: | Thomas Hörndlein <thomas [...] hoerndlein.de> |
Hello,
REST::Client does not work with body content which evaluates to false like this:
$client->PUT('http://example.com/dir/file', 0);
$client->POST('http://example.com/dir/file', 0);
The reason is an incorrect formulated if-condition within the
request-subroutine:
sub request {
…
#build headers
if($content){
$req->content($content);
$req->header('Content-Length', length($content));
}else{
$req->header('Content-Length', 0);
}
…
}
This always evaluates to false if $content is something like 0 or the empty
string ‘’ and so on.
The fix would be testing the length of $content like this:
sub request {
…
#build headers
if(length $content){
$req->content($content);
$req->header('Content-Length', length($content));
}else{
$req->header('Content-Length', 0);
}
…
}
Kind regards,
Thomas