header_ok: Refactor for readability

This commit is contained in:
Richard Hansen 2024-05-17 22:24:12 -04:00
parent adbac91be7
commit 7fe7fd0e18

View file

@ -3775,24 +3775,21 @@ sub nic_updateable {
sub header_ok { sub header_ok {
my ($host, $line) = @_; my ($host, $line) = @_;
$line =~ s/\r?\n.*//s; $line =~ s/\r?\n.*//s;
my $ok = 0; # TODO: What is this leading /s*/? Is it a typo of /\s*/?
my ($result) = ($line =~ qr%^s*HTTP/.*\s+(\d+)%i);
if ($line =~ m%^s*HTTP/.*\s+(\d+)%i) { if (!defined($result)) {
my $result = $1; failed('updating %s: unexpected HTTP response: %s', $host, $line);
return 0;
if ($result =~ m/^2\d\d$/) {
$ok = 1;
} elsif ($result eq '401') { } elsif ($result eq '401') {
failed("updating %s: authentication failed (%s)", $host, $line); failed("updating %s: authentication failed (%s)", $host, $line);
return 0;
} elsif ($result eq '403') { } elsif ($result eq '403') {
failed("updating %s: not authorized (%s)", $host, $line); failed("updating %s: not authorized (%s)", $host, $line);
return 0;
} elsif ($result !~ qr/^2\d\d$/) {
return 0;
} }
return 1;
} else {
failed("updating %s: unexpected line (%s)", $host, $line);
}
return $ok;
} }
###################################################################### ######################################################################