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

Function HandleHeader

engine/dlib/src/dlib/http_client.cpp:440–485  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

438 }
439
440 static void HandleHeader(void* user_data, const char* key, const char* value)
441 {
442 Response* resp = (Response*) user_data;
443
444 if (dmStrCaseCmp(key, "Content-Length") == 0)
445 {
446 resp->m_ContentLength = strtol(value, 0, 10);
447 }
448 else if (dmStrCaseCmp(key, "Content-Range") == 0)
449 {
450 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
451 // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Range
452 sscanf(value, "bytes %d-%d/%d", &resp->m_RangeStart, &resp->m_RangeEnd, &resp->m_DocumentSize);
453 }
454 else if (dmStrCaseCmp(key, "Transfer-Encoding") == 0 && dmStrCaseCmp(value, "chunked") == 0)
455 {
456 resp->m_Chunked = 1;
457 }
458 else if (dmStrCaseCmp(key, "Connection") == 0 && dmStrCaseCmp(value, "close") == 0)
459 {
460 resp->m_CloseConnection = 1;
461 }
462 else if (dmStrCaseCmp(key, "ETag") == 0)
463 {
464 dmStrlCpy(resp->m_ETag, value, sizeof(resp->m_ETag));
465 }
466 else if (dmStrCaseCmp(key, "Cache-Control") == 0)
467 {
468 const char* substr = "max-age=";
469 const char* max_age = strstr(value, "max-age=");
470 if (max_age) {
471 max_age += strlen(substr);
472 resp->m_MaxAge = dmMath::Max(0, atoi(max_age));
473 if (resp->m_MaxAge > HTTP_CLIENT_MAXIMUM_CACHE_AGE)
474 {
475 resp->m_MaxAge = HTTP_CLIENT_MAXIMUM_CACHE_AGE;
476 }
477 }
478 }
479
480 HClient c = resp->m_Client;
481 if (c->m_HttpHeader)
482 {
483 resp->m_Client->m_HttpHeader(resp, c->m_Userdata, resp->m_Status, key, value);
484 }
485 }
486
487 static void HandleContent(void* user_data, int offset)
488 {

Callers

nothing calls this directly

Calls 3

dmStrCaseCmpFunction · 0.85
dmStrlCpyFunction · 0.85
MaxFunction · 0.50

Tested by

no test coverage detected