fix(router): check if Accept header is set before getting value

fix deprecation warnings for getHeader and getHeaders methods

refs #228
This commit is contained in:
Yassine Doghri 2022-08-01 10:13:16 +00:00
parent e66bf44341
commit 10a2ae0248
3 changed files with 9 additions and 4 deletions

View File

@ -69,7 +69,7 @@ if (! function_exists('download_file')) {
true, true,
) )
) { ) {
$newFileUrl = trim($response->getHeader('location')->getValue()); $newFileUrl = trim($response->header('location')->getValue());
$response = $client->get($newFileUrl, [ $response = $client->get($newFileUrl, [
'headers' => [ 'headers' => [
'User-Agent' => 'Castopod/' . CP_VERSION, 'User-Agent' => 'Castopod/' . CP_VERSION,

View File

@ -110,7 +110,12 @@ class Router extends CodeIgniterRouter
$request = Services::request(); $request = Services::request();
$negotiate = Services::negotiator(); $negotiate = Services::negotiator();
$acceptHeader = $request->getHeader('Accept') // Accept header is mandatory
if ($request->header('Accept') === null) {
break;
}
$acceptHeader = $request->header('Accept')
->getValue(); ->getValue();
$parsedHeader = $negotiate->parseHeader($acceptHeader); $parsedHeader = $negotiate->parseHeader($acceptHeader);

View File

@ -272,7 +272,7 @@ $error_id = uniqid('error', true); ?>
<?php endif; ?> <?php endif; ?>
<?php $headers = $request->getHeaders(); ?> <?php $headers = $request->headers(); ?>
<?php if (! empty($headers)) : ?> <?php if (! empty($headers)) : ?>
<h3>Headers</h3> <h3>Headers</h3>
@ -320,7 +320,7 @@ $error_id = uniqid('error', true); ?>
</tr> </tr>
</table> </table>
<?php $headers = $response->getHeaders(); ?> <?php $headers = $response->headers(); ?>
<?php if (! empty($headers)) : ?> <?php if (! empty($headers)) : ?>
<?php natsort($headers) ?> <?php natsort($headers) ?>