Support JSON response in get_simple_config.
This commit is contained in:
parent
b8ab910b81
commit
aa1f7592e8
@ -261,13 +261,7 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<Simpl
|
|||||||
name = is_test ? "tapv3.stel.com" : "apv3.stel.com";
|
name = is_test ? "tapv3.stel.com" : "apv3.stel.com";
|
||||||
}
|
}
|
||||||
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
auto get_config = [](HttpQuery &http_query) -> Result<string> {
|
||||||
VLOG(config_recoverer) << "Receive DNS response " << http_query.content_;
|
auto get_data = [](JsonValue &answer) -> Result<string> {
|
||||||
TRY_RESULT(json, json_decode(http_query.content_));
|
|
||||||
if (json.type() != JsonValue::Type::Object) {
|
|
||||||
return Status::Error("Expected JSON object");
|
|
||||||
}
|
|
||||||
auto &answer_object = json.get_object();
|
|
||||||
TRY_RESULT(answer, get_json_object_field(answer_object, "Answer", JsonValue::Type::Array, false));
|
|
||||||
auto &answer_array = answer.get_array();
|
auto &answer_array = answer.get_array();
|
||||||
vector<string> parts;
|
vector<string> parts;
|
||||||
for (auto &answer_part : answer_array) {
|
for (auto &answer_part : answer_array) {
|
||||||
@ -289,6 +283,24 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<Simpl
|
|||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
if (!http_query.get_arg("Answer").empty()) {
|
||||||
|
VLOG(config_recoverer) << "Receive DNS response " << http_query.get_arg("Answer");
|
||||||
|
TRY_RESULT(answer, json_decode(http_query.get_arg("Answer")));
|
||||||
|
if (answer.type() != JsonValue::Type::Array) {
|
||||||
|
return Status::Error("Expected JSON array");
|
||||||
|
}
|
||||||
|
return get_data(answer);
|
||||||
|
} else {
|
||||||
|
VLOG(config_recoverer) << "Receive DNS response " << http_query.content_;
|
||||||
|
TRY_RESULT(json, json_decode(http_query.content_));
|
||||||
|
if (json.type() != JsonValue::Type::Object) {
|
||||||
|
return Status::Error("Expected JSON object");
|
||||||
|
}
|
||||||
|
auto &answer_object = json.get_object();
|
||||||
|
TRY_RESULT(answer, get_json_object_field(answer_object, "Answer", JsonValue::Type::Array, false));
|
||||||
|
return get_data(answer);
|
||||||
|
}
|
||||||
|
};
|
||||||
return get_simple_config_impl(std::move(promise), scheduler_id,
|
return get_simple_config_impl(std::move(promise), scheduler_id,
|
||||||
PSTRING() << "https://" << address << "?name=" << url_encode(name) << "&type=TXT",
|
PSTRING() << "https://" << address << "?name=" << url_encode(name) << "&type=TXT",
|
||||||
host.str(), {{"Accept", "application/dns-json"}}, prefer_ipv6, std::move(get_config));
|
host.str(), {{"Accept", "application/dns-json"}}, prefer_ipv6, std::move(get_config));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user