/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { // check for debugging locally, which should not require the headers if ($this->app->environment() === 'local' && $request->input(config('jsonapi.identifiers.request.debug'))) { $request->header('Content-type', 'text/html', true); return $next($request); } if (!$this->acceptHeaderValid($request)) { return response('', 406); } if (!$this->contentTypeHeaderValid($request)) { return response('', 415); } return $this->addHeader($next($request)); }
/** * Checks the web eligibility for Platform. If true, Platform * is safe to run in the web. * * @return bool * @throws \Symfony\Component\HttpKernel\Exception\HttpException */ public function checkRunningEligibility() { // If we're running in console, we're always fine to // run Platform except for testing. if ($this->app->runningInConsole()) { return $this->app->environment() !== 'testing'; } if ($this->isInstalled()) { // Now, let's check for database connectivity. If we have no // connectivity, the database connection is probably lost. // This means the service is in fact unavailable. try { $this->app['db']->connection(); return true; } catch (PDOException $e) { throw new HttpException(503, 'Database connection could not be established.'); } } // Check if the path is on the eligibility whitelist return in_array($this->app['request']->path(), $this->eligibilityWhitelist); }
/** * Returns flag on testing enviroment * * @return bool */ public function isTestingEnviroment() { return $this->app->runningInConsole() && $this->app->environment() === 'testing'; }