Skip to content

Commit

Permalink
tweak(citizen-server-impl): always give HTTP headers
Browse files Browse the repository at this point in the history
  • Loading branch information
MoskalykA committed Feb 4, 2025
1 parent 7bcb23d commit c1e23a5
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions code/components/citizen-server-impl/src/HttpScriptFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,43 +116,43 @@ void PerformHttpRequestInternal(fx::ScriptContext& context)
// run a HTTP request
httpClient->DoMethodRequest(method, url, data, options, [evComponent, token, responseCode, responseHeaders](bool success, const char* data, size_t length)
{
if (!success)
{
evComponent->QueueEvent2("__cfx_internal:httpResponse", {}, token, *responseCode, msgpack::type::nil_t{}, std::map<std::string, std::string>(), std::string{ data, length });
}
else
msgpack::zone mz;
auto responseHeaderData = std::map<std::string, msgpack::object>();
for (auto& [key, value] : *responseHeaders)
{
msgpack::zone mz;
auto responseHeaderData = std::map<std::string, msgpack::object>();
for (auto& [key, value] : *responseHeaders)
if (auto it = responseHeaderData.find(key); it != responseHeaderData.end())
{
if (auto it = responseHeaderData.find(key); it != responseHeaderData.end())
// inefficient, but trivial
std::vector<std::string> newVal;

if (it->second.type != msgpack::type::ARRAY)
{
// inefficient, but trivial
std::vector<std::string> newVal;

if (it->second.type != msgpack::type::ARRAY)
{
newVal = {
it->second.as<std::string>(),
value
};
}
else
{
newVal = it->second.as<std::vector<std::string>>();
newVal.push_back(value);
}

responseHeaderData.erase(it);
responseHeaderData.emplace(key, msgpack::object{ newVal, mz });
newVal = {
it->second.as<std::string>(),
value
};
}
else
{
responseHeaderData.emplace(key, msgpack::object{ value, mz });
newVal = it->second.as<std::vector<std::string>>();
newVal.push_back(value);
}

responseHeaderData.erase(it);
responseHeaderData.emplace(key, msgpack::object{ newVal, mz });
}
else
{
responseHeaderData.emplace(key, msgpack::object{ value, mz });
}
}

if (!success)
{
evComponent->QueueEvent2("__cfx_internal:httpResponse", {}, token, *responseCode, msgpack::type::nil_t{}, responseHeaderData, std::string{ data, length });
}
else
{
evComponent->QueueEvent2("__cfx_internal:httpResponse", {}, token, *responseCode, std::string{ data, length }, responseHeaderData, msgpack::type::nil_t{});
}
});
Expand Down

0 comments on commit c1e23a5

Please sign in to comment.