Merge pull request #680 from rhansen/dnsexit2
dnsexit2: Fix parsing of JSON response
This commit is contained in:
commit
ddb04075be
1 changed files with 7 additions and 13 deletions
20
ddclient.in
20
ddclient.in
|
@ -4215,21 +4215,15 @@ sub nic_dnsexit2_update {
|
|||
failed("Full reply\n%s", $reply) unless opt('verbose');
|
||||
next;
|
||||
}
|
||||
|
||||
# Strip HTTP response headers
|
||||
(my $strip_status) = ($reply =~ s/^[\s\S]*?(?=\{"code":)//);
|
||||
debug("strip_status");
|
||||
debug("%s", $strip_status);
|
||||
if ($strip_status) {
|
||||
debug("HTTP headers are stripped.");
|
||||
} else {
|
||||
warning("Unexpected: no HTTP headers stripped!");
|
||||
my $body = ($reply =~ s/^.*?\r?\n\r?\n//sr);
|
||||
my $response = eval { decode_json($body); };
|
||||
if (!$response) {
|
||||
failed("failed to parse response: $@");
|
||||
next;
|
||||
}
|
||||
my $response = decode_json($reply);
|
||||
if (!defined($response->{'code'}) || !defined($response->{'message'})) {
|
||||
failed("Did not receive expected \"code\" and \"message\" keys in server response.");
|
||||
failed("Response:");
|
||||
failed("%s", $response);
|
||||
failed("Did not receive expected 'code' and 'message' keys in server response:\n%s",
|
||||
$body);
|
||||
next;
|
||||
}
|
||||
my %codemeaning = (
|
||||
|
|
Loading…
Reference in a new issue