header_ok: Log all non-2xx HTTP status codes
This commit is contained in:
parent
7fe7fd0e18
commit
211d59fccc
2 changed files with 13 additions and 13 deletions
17
ddclient.in
17
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;
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in a new issue