Lua: Optimize http header setting code (#18904)

This commit is contained in:
Jimmy Yin 2018-08-06 12:37:25 +08:00 committed by leda
parent d41820b14b
commit 4a3263d294
1 changed files with 1 additions and 17 deletions

View File

@ -262,23 +262,7 @@ void LuaMinXmlHttpRequest::_setHttpRequestHeader()
for (auto it = _requestHeader.begin(); it != _requestHeader.end(); ++it)
{
const char* first = it->first.c_str();
const char* second = it->second.c_str();
size_t len = sizeof(char) * (strlen(first) + 3 + strlen(second));
char* test = (char*) malloc(len);
if (test != nullptr) //should check failure of malloc or it could be an undefined behaviour
{
memset(test, 0,len);
strcpy(test, first);
strcpy(test + strlen(first) , ": ");
strcpy(test + strlen(first) + 2, second);
header.push_back(test);
free(test);
}
header.push_back(it->first + ": " + it->second);
}
if (!header.empty())