MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / getAsync

Method getAsync

Source/Http/HttpServer.cpp:1347–1392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1345}
1346
1347HttpClient::RequestId HttpClient::getAsync(String url, float timeout, const ContentHandler& callback) {
1348 if (_stopped.load(std::memory_order_relaxed)) {
1349 callback(std::nullopt);
1350 return 0;
1351 }
1352 auto request = register_http_client_request();
1353 if (!request) {
1354 callback(std::nullopt);
1355 return 0;
1356 }
1357 SharedAsyncThread.run([request, timeout, urlStr = url.toString(), callback]() {
1358 std::vector<std::string> headerNames;
1359 std::vector<std::string> headerValues;
1360 std::vector<const char*> headerNamePtrs;
1361 std::vector<const char*> headerValuePtrs;
1362 DoraXrtHttpResponse response;
1363 prepare_xrt_http_headers(headerNames, headerValues, headerNamePtrs, headerValuePtrs, {});
1364 auto status = DoraXrtHttpExecute(
1365 "GET",
1366 urlStr.c_str(),
1367 headerNamePtrs.data(),
1368 headerValuePtrs.data(),
1369 headerNamePtrs.size(),
1370 nullptr,
1371 0,
1372 to_timeout_ms(timeout),
1373 0,
1374 should_cancel_xrt_http,
1375 request.get(),
1376 &response);
1377 if (status != 0 || response.statusCode < 200 || response.statusCode >= 400) {
1378 Info("failed to do HTTP GET \"{}\"; network status: {}, HTTP status: {}", urlStr, DoraXrtHttpStatusName(status), response.statusCode);
1379 SharedApplication.invokeInLogic([callback]() {
1380 callback(std::nullopt);
1381 });
1382 } else {
1383 std::string body(response.body ? response.body : "", response.bodyLen);
1384 SharedApplication.invokeInLogic([callback, body = std::move(body)]() {
1385 callback(body);
1386 });
1387 }
1388 DoraXrtHttpResponseFree(&response);
1389 unregister_http_client_request(request);
1390 });
1391 return request->id;
1392}
1393
1394HttpClient::RequestId HttpClient::downloadAsync(String url, String filePath, float timeout, const std::function<bool(bool interrupted, uint64_t current, uint64_t total)>& progress) {
1395 if (_stopped.load(std::memory_order_relaxed)) {

Callers

nothing calls this directly

Calls 15

prepare_xrt_http_headersFunction · 0.85
DoraXrtHttpExecuteFunction · 0.85
to_timeout_msFunction · 0.85
InfoStruct · 0.85
DoraXrtHttpStatusNameFunction · 0.85
moveFunction · 0.85
DoraXrtHttpResponseFreeFunction · 0.85
invokeInLogicMethod · 0.80
loadMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected