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

Function SendRequest

engine/dlib/src/dlib/http_client.cpp:608–709  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

606
607
608 static dmSocket::Result SendRequest(HClient client, HResponse response, const char* encoded_path, const char* method)
609 {
610 dmSocket::Result sock_res;
611 uint32_t send_content_length = 0;
612 int chunked = 0;
613
614 HTTP_CLIENT_SENDALL_AND_BAIL(method);
615 HTTP_CLIENT_SENDALL_AND_BAIL(" ")
616 HTTP_CLIENT_SENDALL_AND_BAIL(encoded_path)
617 HTTP_CLIENT_SENDALL_AND_BAIL(" HTTP/1.1\r\n")
618 HTTP_CLIENT_SENDALL_AND_BAIL("Host: ");
619 HTTP_CLIENT_SENDALL_AND_BAIL(client->m_HostURI.m_Hostname);
620 HTTP_CLIENT_SENDALL_AND_BAIL("\r\n");
621
622 if (client->m_HttpWriteHeaders) {
623 Result header_result = client->m_HttpWriteHeaders(response, client->m_Userdata);
624 if (header_result != RESULT_OK) {
625 goto bail;
626 }
627 }
628
629#if !defined(DM_NO_HTTP_CACHE)
630 if (!client->m_IgnoreCache && client->m_HttpCache)
631 {
632 char etag[dmHttpCache::MAX_TAG_LEN] = "";
633 dmHttpCache::Result cache_result = dmHttpCache::GetETag(client->m_HttpCache, client->m_CacheKey, etag, sizeof(etag));
634 if (cache_result == dmHttpCache::RESULT_OK)
635 {
636 HTTP_CLIENT_SENDALL_AND_BAIL("If-None-Match: ");
637 HTTP_CLIENT_SENDALL_AND_BAIL(etag);
638 HTTP_CLIENT_SENDALL_AND_BAIL("\r\n");
639 }
640 }
641#endif
642
643 if (strcmp(method, "POST") == 0 || strcmp(method, "PUT") == 0 || strcmp(method, "PATCH") == 0) {
644 send_content_length = client->m_HttpSendContentLength(response, client->m_Userdata);
645
646 if (client->m_Secure && send_content_length > MAX_HTTPS_POST_CHUNK_SIZE)
647 {
648 chunked = 1;
649 }
650 // disable chunked transfer encoding if explicitly disabled by the user
651 if (client->m_ChunkedTransfer == 0)
652 {
653 chunked = 0;
654 }
655
656 // If we want to send more that this, we need to send it chunked
657 if (chunked) {
658 HTTP_CLIENT_SENDALL_AND_BAIL("Transfer-Encoding: chunked\r\n");
659 } else {
660 char buf[64];
661 dmSnPrintf(buf, sizeof(buf), "Content-Length: %d\r\n", send_content_length);
662 HTTP_CLIENT_SENDALL_AND_BAIL(buf);
663 }
664 }
665

Callers 1

DoDoRequestFunction · 0.85

Calls 3

dmSnPrintfFunction · 0.85
MinFunction · 0.85
GetETagFunction · 0.70

Tested by

no test coverage detected