Return correct headers

This commit is contained in:
James Cole
2025-01-25 04:48:51 +01:00
parent 6f63ddf5b0
commit 663202bfc6
16 changed files with 31 additions and 21 deletions

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Api\V1\Controllers;
use Carbon\Carbon;
use Carbon\Exceptions\InvalidFormatException;
use FireflyIII\Exceptions\BadHttpHeaderException;
use FireflyIII\Models\Preference;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Support\Facades\Amount;
@@ -60,11 +61,13 @@ abstract class Controller extends BaseController
use ValidatesRequests;
protected const string CONTENT_TYPE = 'application/vnd.api+json';
protected const string JSON_CONTENT_TYPE = 'application/json';
/** @var array<int, string> */
protected array $allowedSort;
protected ParameterBag $parameters;
protected bool $convertToNative = false;
protected array $accepts = ['application/json'];
protected TransactionCurrency $nativeCurrency;
/**
@@ -82,9 +85,15 @@ abstract class Controller extends BaseController
$this->convertToNative = Amount::convertToNative();
$this->nativeCurrency = Amount::getNativeCurrency();
app()->setLocale($language);
}
// filter down what this endpoint accepts.
if (!$request->accepts($this->accepts)) {
throw new BadHttpHeaderException(sprintf('Sorry, Accept header "%s" is not something this endpoint can provide.', $request->header('Accept')));
}
return $next($request);
}
);