mirror of https://github.com/axmolengine/axmol.git
Lua: Optimize http header setting code (#18904)
This commit is contained in:
parent
d41820b14b
commit
4a3263d294
|
@ -262,23 +262,7 @@ void LuaMinXmlHttpRequest::_setHttpRequestHeader()
|
||||||
|
|
||||||
for (auto it = _requestHeader.begin(); it != _requestHeader.end(); ++it)
|
for (auto it = _requestHeader.begin(); it != _requestHeader.end(); ++it)
|
||||||
{
|
{
|
||||||
const char* first = it->first.c_str();
|
header.push_back(it->first + ": " + it->second);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!header.empty())
|
if (!header.empty())
|
||||||
|
|
Loading…
Reference in New Issue