fix(auth): extend stream-based HTTP to POST requests in OidcHttpGateway

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
aminovfariz
2026-05-28 13:14:19 +02:00
parent 4e51d9e882
commit ec596d35d4

View File

@@ -11,32 +11,41 @@ class OidcHttpGateway
*/ */
public function call(string $method, string $url, mixed $data = '', array $headers = []): array public function call(string $method, string $url, mixed $data = '', array $headers = []): array
{ {
if (strtoupper($method) === 'GET') { return $this->callWithStream(strtoupper($method), $url, $data, $headers);
return $this->getWithStream($url, $headers);
}
return Curl::call($method, $url, $data, $headers);
} }
/** /**
* @param array<string, string> $headers * @param array<string, string> $headers
*/ */
private function getWithStream(string $url, array $headers): array private function callWithStream(string $method, string $url, mixed $data, array $headers): array
{ {
$headerLines = []; $headerLines = [];
foreach ($headers as $key => $value) { foreach ($headers as $key => $value) {
$headerLines[] = $key . ': ' . $value; $headerLines[] = $key . ': ' . $value;
} }
$httpContext = [
'method' => $method,
'header' => implode("\r\n", $headerLines),
'ignore_errors' => true,
];
if ($method === 'POST') {
$body = is_array($data) ? http_build_query($data) : (string) $data;
$httpContext['content'] = $body;
if (!isset($headers['Content-Type'])) {
$httpContext['header'] .= "\r\nContent-Type: application/x-www-form-urlencoded";
}
}
$ctx = stream_context_create([ $ctx = stream_context_create([
'http' => [ 'http' => $httpContext,
'method' => 'GET',
'header' => implode("\r\n", $headerLines),
'ignore_errors' => true,
],
'ssl' => [ 'ssl' => [
'verify_peer' => true, 'verify_peer' => true,
'verify_peer_name' => true, 'verify_peer_name' => true,
], ],
]); ]);
$body = @file_get_contents($url, false, $ctx); $body = @file_get_contents($url, false, $ctx);
$status = 0; $status = 0;
$responseHeaders = []; $responseHeaders = [];