Merge pull request #680 from rhansen/dnsexit2

dnsexit2: Fix parsing of JSON response
This commit is contained in:
Richard Hansen 2024-05-31 03:27:34 -04:00 committed by GitHub
commit ddb04075be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4215,21 +4215,15 @@ sub nic_dnsexit2_update {
failed("Full reply\n%s", $reply) unless opt('verbose'); failed("Full reply\n%s", $reply) unless opt('verbose');
next; next;
} }
my $body = ($reply =~ s/^.*?\r?\n\r?\n//sr);
# Strip HTTP response headers my $response = eval { decode_json($body); };
(my $strip_status) = ($reply =~ s/^[\s\S]*?(?=\{"code":)//); if (!$response) {
debug("strip_status"); failed("failed to parse response: $@");
debug("%s", $strip_status); next;
if ($strip_status) {
debug("HTTP headers are stripped.");
} else {
warning("Unexpected: no HTTP headers stripped!");
} }
my $response = decode_json($reply);
if (!defined($response->{'code'}) || !defined($response->{'message'})) { if (!defined($response->{'code'}) || !defined($response->{'message'})) {
failed("Did not receive expected \"code\" and \"message\" keys in server response."); failed("Did not receive expected 'code' and 'message' keys in server response:\n%s",
failed("Response:"); $body);
failed("%s", $response);
next; next;
} }
my %codemeaning = ( my %codemeaning = (