@@ -74,6 +74,10 @@ SimpleCurlGet::GetStatus SimpleCurlGet::perform_start(const std::string &url) {
7474 if (rv != CURLE_OK) {
7575 throw CurlException (" Failed to set CURLOPT_TIMEOUT." );
7676 }
77+ rv = curl_easy_setopt (m_curl.get (), CURLOPT_FOLLOWLOCATION, 1L );
78+ if (rv != CURLE_OK) {
79+ throw CurlException (" Failed to set CURLOPT_FOLLOWLOCATION." );
80+ }
7781
7882 {
7983 auto mres = curl_multi_add_handle (m_curl_multi.get (), m_curl.get ());
@@ -85,6 +89,20 @@ SimpleCurlGet::GetStatus SimpleCurlGet::perform_start(const std::string &url) {
8589 return perform_continue ();
8690}
8791
92+ std::string SimpleCurlGet::get_url () const {
93+ if (!m_curl) {
94+ return " " ;
95+ }
96+
97+ char *url = nullptr ;
98+ auto rv = curl_easy_getinfo (m_curl.get (), CURLINFO_EFFECTIVE_URL, &url);
99+ if (rv != CURLE_OK) {
100+ return " " ;
101+ }
102+
103+ return std::string (url);
104+ }
105+
88106SimpleCurlGet::GetStatus SimpleCurlGet::perform_continue () {
89107 int still_running;
90108 auto resm = curl_multi_perform (m_curl_multi.get (), &still_running);
@@ -649,17 +667,22 @@ std::unique_ptr<AsyncStatus> Validator::get_public_keys_from_web_continue(
649667 picojson::value json_obj;
650668 auto err = picojson::parse (json_obj, metadata);
651669 if (!err.empty ()) {
652- throw JsonException (err);
670+ throw JsonException (
671+ " JSON parse failure when downloading from the metadata URL " +
672+ status->m_cget ->get_url () + " : " + err);
653673 }
654674 if (!json_obj.is <picojson::object>()) {
655- throw JsonException (
656- " Metadata resource contains improperly-formatted JSON." );
675+ throw JsonException (" Metadata resource " +
676+ status->m_cget ->get_url () +
677+ " contains "
678+ " improperly-formatted JSON." );
657679 }
658680 auto top_obj = json_obj.get <picojson::object>();
659681 auto iter = top_obj.find (" jwks_uri" );
660682 if (iter == top_obj.end () || (!iter->second .is <std::string>())) {
661- throw JsonException (
662- " Metadata resource is missing 'jwks_uri' string value" );
683+ throw JsonException (" Metadata resource " +
684+ status->m_cget ->get_url () +
685+ " is missing 'jwks_uri' string value" );
663686 }
664687 auto jwks_uri = iter->second .get <std::string>();
665688 status->m_has_metadata = true ;
@@ -684,7 +707,9 @@ std::unique_ptr<AsyncStatus> Validator::get_public_keys_from_web_continue(
684707 auto err = picojson::parse (json_obj, metadata);
685708 status->m_cget .reset ();
686709 if (!err.empty ()) {
687- throw JsonException (err);
710+ throw JsonException (" JSON parse failure when downloading from the "
711+ " public key URL " +
712+ status->m_cget ->get_url () + " : " + err);
688713 }
689714
690715 auto now = std::time (NULL );
0 commit comments