diff --git a/ddclient.in b/ddclient.in index cc21be6..84d8e3d 100755 --- a/ddclient.in +++ b/ddclient.in @@ -3776,17 +3776,16 @@ sub header_ok { my ($host, $line) = @_; $line =~ s/\r?\n.*//s; # TODO: What is this leading /s*/? Is it a typo of /\s*/? - my ($result) = ($line =~ qr%^s*HTTP/.*\s+(\d+)%i); - if (!defined($result)) { + my ($code, $msg) = ($line =~ qr%^s*HTTP/.*\s+(\d+)\s*(?:\s+([^\s].*))?$%i); + if (!defined($code)) { failed('updating %s: unexpected HTTP response: %s', $host, $line); return 0; - } elsif ($result eq '401') { - failed("updating %s: authentication failed (%s)", $host, $line); - return 0; - } elsif ($result eq '403') { - failed("updating %s: not authorized (%s)", $host, $line); - return 0; - } elsif ($result !~ qr/^2\d\d$/) { + } elsif ($code !~ qr/^2\d\d$/) { + my %msgs = ( + '401' => 'authentication failed', + '403' => 'not authorized', + ); + failed('updating %s: %s %s', $host, $code, $msg // $msgs{$code} // ''); return 0; } return 1; diff --git a/t/header_ok.pl b/t/header_ok.pl index 5797341..197cc8d 100644 --- a/t/header_ok.pl +++ b/t/header_ok.pl @@ -35,14 +35,14 @@ my @test_cases = ( want => 1, }, { - desc => '401 not OK', - input => 'HTTP/1.1 401 bad', + desc => '401 not OK, fallback message', + input => 'HTTP/1.1 401 ', want => 0, wantmsg => qr/authentication failed/, }, { - desc => '403 not OK', - input => 'HTTP/1.1 403 bad', + desc => '403 not OK, fallback message', + input => 'HTTP/1.1 403 ', want => 0, wantmsg => qr/not authorized/, }, @@ -50,6 +50,7 @@ my @test_cases = ( desc => 'other 4xx not OK', input => 'HTTP/1.1 456 bad', want => 0, + wantmsg => qr/bad/, }, { desc => 'only first line is logged on error',