Skip to content

Commit b187af1

Browse files
🐛 fix: 'Content-Type' check and add header validation
1 parent 249ffed commit b187af1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Changelog
8383
[Release 1.3.0](https://github.com/efipay/sdk-php-apis-efi/releases/tag/1.3.0) (2023-10-12)
8484
--------------------------
8585
* Added option to enter the certificate password through the "pwdCertificate" parameter
86-
* Added option to enable/disable cache to reuse authentication hrough the "cache" parameter
86+
* Added option to enable/disable cache to reuse authentication through the "cache" parameter
8787
* Parameters "client_id" and "client_secret" changed following the camel case convention, that is, "clientId" and "clientSecret", but the old names are accepted
8888
* Support symfony/cache v6
8989

src/Efi/Request.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,11 @@ private function checkCertificateExpiration(string $validToTime): void
173173

174174
public function send(string $method, string $route, array $requestOptions)
175175
{
176+
if (!empty($this->config['debug']) && $this->config['debug'] === true) {
177+
echo '<br>[SDK] version: "' . ($requestOptions['api-sdk'] ?? $requestOptions['headers']['api-sdk']) . '" [REQUEST] method: "' . $method . '" url: "' . $this->config['baseUri'] . '" route: "' . $route . '"<br>';
178+
}
176179
try {
177180
$this->applyCertificateAndHeaders($requestOptions);
178-
179181
$response = $this->client->request($method, $route, $requestOptions);
180182
return $this->processResponse($response);
181183
} catch (ClientException $e) {
@@ -235,9 +237,9 @@ private function processResponse($response)
235237
{
236238
$headersResponse = $this->config['responseHeaders'] ? $response->getHeaders() : $response->getHeader('Content-Type');
237239

238-
$contentType = isset($headersResponse['Content-Type'][0]) ? $headersResponse['Content-Type'][0] : $headersResponse[0];
240+
$contentType = !empty($headersResponse['Content-Type'][0]) ? $headersResponse['Content-Type'][0] : (!empty($headersResponse[0]) ? $headersResponse[0] : null);
239241

240-
if (stristr($contentType, 'application/json')) {
242+
if (!empty($contentType) && stristr($contentType, 'application/json')) {
241243
$bodyResponse = json_decode($response->getBody(), true);
242244
} else {
243245
$bodyResponse = $response->getBody()->getContents();

0 commit comments

Comments
 (0)