/** * Parse the accept header. * * @return void */ protected function parseAcceptHeader() { if ($this->accept) { return; } $this->accept = static::$acceptParser->parse($this); }
/** * Validate the accept header on the request. If this fails it will throw * an HTTP exception that will be caught by the middleware. This * validator should always be run last and must not return * a success boolean. * * @param \Illuminate\Http\Request $request * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * * @return bool */ public function validate(Request $request) { try { $this->accept->parse($request, $this->strict); } catch (BadRequestHttpException $exception) { if ($request->getMethod() === 'OPTIONS') { return true; } throw $exception; } }
public function testApiVersionWithoutVSuffix() { $parser = new Accept('vnd', 'api', '1.0', 'json'); $accept = $parser->parse($this->createRequest('foo', 'GET', ['accept' => 'application/vnd.api.1.0+xml'])); $this->assertEquals('api', $accept['subtype']); $this->assertEquals('1.0', $accept['version']); $this->assertEquals('xml', $accept['format']); }
public function getCurrentAcceptHeader($request = null) { if (!isset($request)) { $request = Request::instance(); } $config = $this->app['config']['api']; $acceptClass = new Accept($config['standardsTree'], $config['subtype'], $config['version'], $config['defaultFormat']); return $acceptClass->parse($request); }
/** * Dispatch a request via the adapter. * * @param \Dingo\Api\Http\Request $request * * @throws \Exception * * @return \Dingo\Api\Http\Response */ public function dispatch(Request $request) { $this->currentRoute = null; $accept = $this->accept->parse($request); $this->container->instance('Dingo\\Api\\Http\\Request', $request); $this->routesDispatched++; try { $response = $this->adapter->dispatch($request, $accept['version']); } catch (Exception $exception) { if ($request instanceof InternalRequest) { throw $exception; } $response = $this->exception->handle($exception); } return $this->prepareResponse($response, $request, $accept['format']); }
/** * Validate the accept header on the request. If this fails it will throw * an HTTP exception that will be caught by the middleware. This * validator should always be run last and must not return * a success boolean. * * @param \Illuminate\Http\Request $request * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * * @return void */ public function validate(Request $request) { $this->accept->parse($request, $this->strict); }