mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Sort out cURL timeouts and increase default
This commit is contained in:
parent
3560691c0a
commit
34888a914e
8 changed files with 18 additions and 73 deletions
|
@ -17,56 +17,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
|
||||
#include "convert_json.h"
|
||||
#include "content/mods.h"
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "settings.h"
|
||||
#include "httpfetch.h"
|
||||
#include "porting.h"
|
||||
|
||||
Json::Value fetchJsonValue(const std::string &url,
|
||||
std::vector<std::string> *extra_headers)
|
||||
{
|
||||
HTTPFetchRequest fetch_request;
|
||||
HTTPFetchResult fetch_result;
|
||||
fetch_request.url = url;
|
||||
fetch_request.caller = HTTPFETCH_SYNC;
|
||||
|
||||
if (extra_headers != NULL)
|
||||
fetch_request.extra_headers = *extra_headers;
|
||||
|
||||
httpfetch_sync(fetch_request, fetch_result);
|
||||
|
||||
if (!fetch_result.succeeded) {
|
||||
return Json::Value();
|
||||
}
|
||||
Json::Value root;
|
||||
std::istringstream stream(fetch_result.data);
|
||||
|
||||
Json::CharReaderBuilder builder;
|
||||
builder.settings_["collectComments"] = false;
|
||||
std::string errs;
|
||||
|
||||
if (!Json::parseFromStream(builder, stream, &root, &errs)) {
|
||||
errorstream << "URL: " << url << std::endl;
|
||||
errorstream << "Failed to parse json data " << errs << std::endl;
|
||||
if (fetch_result.data.size() > 100) {
|
||||
errorstream << "Data (" << fetch_result.data.size()
|
||||
<< " bytes) printed to warningstream." << std::endl;
|
||||
warningstream << "data: \"" << fetch_result.data << "\"" << std::endl;
|
||||
} else {
|
||||
errorstream << "data: \"" << fetch_result.data << "\"" << std::endl;
|
||||
}
|
||||
return Json::Value();
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
void fastWriteJson(const Json::Value &value, std::ostream &to)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue