Exemplo n.º 1
0
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$response->headers()->has('Content-Type') || !$response->headers()->get('Content-Type') instanceof ContentType) {
         return $attributes;
     }
     return $attributes->put(self::key(), new Attribute(self::key(), MediaType::fromString((string) $response->headers()->get('Content-Type')->values()->current()), $this->clock->now()->elapsedSince($start)->milliseconds()));
 }
Exemplo n.º 2
0
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$response->headers()->has('Content-Type') || !($header = $response->headers()->get('Content-Type')) instanceof ContentType || !$header->values()->current()->parameters()->contains('charset')) {
         return $attributes;
     }
     return $attributes->put(self::key(), new Attribute(self::key(), $header->values()->current()->parameters()->get('charset')->value(), $this->clock->now()->elapsedSince($start)->milliseconds()));
 }
Exemplo n.º 3
0
 private function merge(MapInterface $http, MapInterface $html) : MapInterface
 {
     if (!$http->contains(HttpParser::key())) {
         return $html;
     }
     if (!$html->contains(HtmlParser::key())) {
         return $http;
     }
     return $http->put(self::key(), $http->get(HttpParser::key())->merge($html->get(HtmlParser::key())));
 }
Exemplo n.º 4
0
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$response->headers()->has('Link') || !$response->headers()->get('Link') instanceof Link) {
         return $attributes;
     }
     $links = $response->headers()->get('Link')->values()->filter(function (LinkValue $value) : bool {
         return $value->relationship() === 'canonical';
     });
     if ($links->size() !== 1) {
         return $attributes;
     }
     return $attributes->put(self::key(), new Attribute(self::key(), $this->resolver->resolve($request, $attributes, $links->current()->url()), $this->clock->now()->elapsedSince($start)->milliseconds()));
 }
Exemplo n.º 5
0
 public function parse(RequestInterface $request, ResponseInterface $response, MapInterface $attributes) : MapInterface
 {
     $start = $this->clock->now();
     if (!$response->headers()->has('Cache-Control')) {
         return $attributes;
     }
     $directives = $response->headers()->get('Cache-Control')->values()->filter(function (HeaderValueInterface $value) : bool {
         return $value instanceof SharedMaxAge;
     });
     if ($directives->size() !== 1) {
         return $attributes;
     }
     return $attributes->put(self::key(), new Attribute(self::key(), $this->clock->now()->goForward(new Second($directives->current()->age())), $this->clock->now()->elapsedSince($start)->milliseconds()));
 }