This commit is contained in:
2026-01-05 14:34:34 +02:00
parent f886350eb1
commit 2b91057589
8 changed files with 111 additions and 61 deletions

View File

@@ -122,7 +122,6 @@ readSocket:
szCharBuffer.Resize(nPreviousSize+n);
V_memcpy((char*)szCharBuffer.GetMemory()+nPreviousSize, response, n);
nPreviousSize += n;
V_printf("%s\n",response);
// HTTP 1.0 reacts either to socket being closed or Content-Lenght
// HTTP 1.1 has Transfer-Encoding: chunked, which we need to respect
@@ -152,6 +151,9 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData
HTTPResponse_t response = {};
CUtlVector<HTTPHeaderParam_t> headers = {};
CUtlBuffer<char> data = {};
if (!szMessage)
return {};
// Parse header
while (*pcCurrentCharacter)
{
@@ -201,19 +203,21 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData
}
bool bParseInChunks = false;
uint64_t uBodySize;
uint64_t uBodySize = 0;
// check content lenght
for ( int i = 0; i < response.m_params.GetSize(); i++ )
for ( int i = 0; i < headers.GetSize(); i++ )
{
if ( !V_stricmp( response.m_params[i].m_szParamName, "Content-Length" ) )
if ( !V_stricmp( headers[i].m_szParamName, "Content-Length" ) )
{
uBodySize = atoll(response.m_params[i].m_szValue);
V_printf("%s\n",headers[i].m_szValue.GetString());
uBodySize = atoll(headers[i].m_szValue);
bParseInChunks = false;
};
if ( !V_stricmp( response.m_params[i].m_szParamName, "Transfer-Encoding" ) )
if ( !V_stricmp( headers[i].m_szParamName, "Transfer-Encoding" ) )
{
if ( !V_stricmp( response.m_params[i].m_szValue, "Chunked" ) )
if ( !V_stricmp( headers[i].m_szValue, "Chunked" ) )
{
bParseInChunks = true;
};
@@ -223,6 +227,11 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData
if ( !bParseInChunks )
{
uint32_t nDataLen = uDataSize-(pcCurrentCharacter-szMessage);
if (nDataLen < uBodySize)
{
response.m_bIsComplete = false;
return response;
}
data = CUtlBuffer<char>(nDataLen+1);
V_memcpy(data.GetMemory(), pcCurrentCharacter, nDataLen);
data[nDataLen] = 0;
@@ -232,6 +241,7 @@ HTTPResponse_t CHTTPClient::ParseResponse( const char *szMessage, uint32_t uData
response.m_params[i] = headers[i];
}
response.m_message = data;
response.m_bIsComplete = true;
} else {
szBuffer = "";