Issue Description
When using FiveM’s native PerformHttpRequest
, response headers are not passed to the callback function for non-200 status codes, despite headers being present in the actual HTTP response.
Reproduction Steps
-
Use FiveM’s
PerformHttpRequest
native -
Make a request that results in a non-200 status code (e.g., 404)
-
Check headers parameter in callback
Code Example
PerformHttpRequest('http://127.0.0.1:8000/nonexistent', function(status, body, headers, errorData)
print(json.encode(headers)) -- Prints: []
end, 'GET', '', {
['Content-Type'] = 'application/json',
['Accept'] = 'application/json'
})
Current Behavior
-
Success (200): Headers are properly passed to callback
-
Error (non-200): Headers parameter is an empty table
[]
Expected Behavior
Response headers should be passed to the callback regardless of status code.
Verification
Same request with curl shows headers are present:
$ curl -X GET 'http://127.0.0.1:8000/nonexistent' \
--header 'Accept: application/json' \
--include
HTTP/1.0 404 Not Found
Host: 127.0.0.1:8000
Connection: close
X-Powered-By: PHP/8.3.8
Cache-Control: no-cache, private
Date: Tue, 14 Jan 2025 02:27:34 GMT
Content-Type: application/json
X-Request-Id: a61c670e-c10a-46ce-a56e-46129423e6d1
Impact
Unable to access important response headers in error cases:
-
Request IDs for error tracking
-
Rate limit information
-
Authentication headers
-
Custom application headers
Source Code Reference
The issue can be found in HttpScriptFunctions.cpp:
if (!success)
{
evComponent->QueueEvent2("__cfx_internal:httpResponse", {}, token, *responseCode, msgpack::type::nil_t{}, std::map<std::string, std::string>(), std::string{ data, length });
}
In error cases, an empty map is passed as the headers parameter (std::map<std::string, std::string>()
), discarding the actual response headers that were received.
Environment
-
FiveM Artifact: 7290
-
OS: Windows 11 Pro 22631