Beispiel #1
0
 /**
  * {@inheritdoc}
  *
  * @throws PreconditionFailedException
  */
 public function verify(ServerRequestInterface $request, HttpResource $definition)
 {
     if ((string) $request->method() !== MethodInterface::GET && $request->headers()->has('Range')) {
         throw new PreconditionFailedException();
     }
     if (!$definition->isRangeable() && $request->headers()->has('Range')) {
         throw new PreconditionFailedException();
     }
 }
 /**
  * {@inheritdoc}
  *
  * @throws UnsupportedMediaTypeException
  */
 public function verify(ServerRequestInterface $request, HttpResource $definition)
 {
     if (!$request->headers()->has('Content-Type')) {
         return;
     }
     $types = $this->formats->mediaTypes()->reduce([], function (array $carry, MediaType $type) {
         $carry[] = (string) $type;
         return $carry;
     });
     $best = $this->negotiator->getBest((string) $request->headers()->get('Content-Type')->values()->join(', '), $types);
     if (!$best instanceof Accept) {
         throw new UnsupportedMediaTypeException();
     }
 }
 /**
  * @param Formats $formats
  * @param ServerRequestInterface $request
  *
  * @return MapInterface<string, HeaderInterface>
  */
 private function buildHeaderFrom(Formats $formats, ServerRequestInterface $request) : MapInterface
 {
     $map = new Map('string', HeaderInterface::class);
     $format = $formats->matching((string) $request->headers()->get('Accept')->values()->join(', '));
     return $map->put('Content-Type', new ContentType(new ContentTypeValue($format->preferredMediaType()->topLevel(), $format->preferredMediaType()->subType(), new Map('string', ParameterInterface::class))));
 }