MCPcopy Create free account
hub / github.com/defold/defold / Get

Function Get

engine/dlib/src/dlib/http_client.cpp:1286–1339  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1284 }
1285
1286 Result Get(HClient client, const char* path)
1287 {
1288 client->m_RequestStart = dmTime::GetMonotonicTime();
1289
1290 Result r;
1291
1292#if !defined(DM_NO_HTTP_CACHE)
1293 if (!client->m_IgnoreCache && client->m_HttpCache)
1294 {
1295 dmHttpCache::ConsistencyPolicy policy = dmHttpCache::GetConsistencyPolicy(client->m_HttpCache);
1296 dmHttpCache::EntryInfo info;
1297
1298 dmHttpCache::Result cache_r = dmHttpCache::GetInfo(client->m_HttpCache, client->m_CacheKey, &info);
1299 if (cache_r == dmHttpCache::RESULT_OK) {
1300 bool ok_etag = info.m_Verified && policy == dmHttpCache::CONSISTENCY_POLICY_TRUST_CACHE;
1301 if ((ok_etag || info.m_Valid)) {
1302 // We have a cache and trust the content of the cache
1303 // OR
1304 // the entry is valid in terms of max-age
1305 r = HandleCachedVerified(client, &info);
1306 if (r == RESULT_NOT_200_OK) {
1307 return r;
1308 }
1309 }
1310 }
1311 }
1312#endif
1313
1314 for (int i = 0; i < client->m_MaxGetRetries; ++i)
1315 {
1316 r = DoRequest(client, path, "GET");
1317 if (r == RESULT_UNEXPECTED_EOF ||
1318 (r == RESULT_SOCKET_ERROR && (client->m_SocketResult == dmSocket::RESULT_CONNRESET
1319 || client->m_SocketResult == dmSocket::RESULT_WOULDBLOCK
1320 || client->m_SocketResult == dmSocket::RESULT_PIPE)))
1321 {
1322 if (HasRequestTimedOut(client)) {
1323 return r;
1324 }
1325
1326 // Try again
1327 if (i < client->m_MaxGetRetries - 1) {
1328 client->m_Statistics.m_Reconnections++;
1329 client->m_RequestStart = dmTime::GetMonotonicTime();
1330 dmLogInfo("HTTPCLIENT: Connection lost, reconnecting. (%d/%d)", i + 1, client->m_MaxGetRetries - 1);
1331 }
1332 }
1333 else
1334 {
1335 return r;
1336 }
1337 }
1338 return r;
1339 }
1340
1341 Result Post(HClient client, const char* path)
1342 {

Callers 3

HandleCachedFunction · 0.70
HandleCachedVerifiedFunction · 0.70
RequestFunction · 0.70

Calls 6

HandleCachedVerifiedFunction · 0.85
DoRequestFunction · 0.85
HasRequestTimedOutFunction · 0.85
GetMonotonicTimeFunction · 0.70
GetConsistencyPolicyFunction · 0.70
GetInfoFunction · 0.70

Tested by

no test coverage detected