Exemplo n.º 1
0
 public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain)
 {
     $filterChain->handle($request, $response, $filterChain);
     if (!$response->hasHeader('Content-MD5')) {
         $response->setHeader('Content-MD5', md5(Util::toString($response->getBody())));
     }
 }
Exemplo n.º 2
0
 protected function fill()
 {
     if (!$this->isFilled) {
         $this->data = Util::toString($this->source);
         $this->isFilled = true;
     }
 }
Exemplo n.º 3
0
 protected function getBodyAsString(RequestInterface $request)
 {
     $body = Util::toString($request->getBody());
     if (empty($body)) {
         $body = null;
     }
     return $body;
 }
Exemplo n.º 4
0
 public function onResponseSend(ResponseSendEvent $event)
 {
     $code = $event->getResponse()->getStatusCode();
     $code = isset(Http::$codes[$code]) ? $code : 200;
     $this->logger->info('Send response ' . $code);
     if ($this->debug) {
         $body = Util::toString($event->getResponse()->getBody());
         if (!empty($body)) {
             $this->logger->debug($body);
         }
     }
 }
Exemplo n.º 5
0
 public function handle(RequestInterface $request, ResponseInterface $response, FilterChainInterface $filterChain)
 {
     $key = $this->getCacheKey($request);
     if (!empty($key)) {
         $item = $this->cache->getItem($key);
         if ($item->isHit()) {
             // serve cache response
             $resp = $item->get();
             $response->setHeaders($resp['headers']);
             $response->getBody()->write($resp['body']);
         } else {
             $filterChain->handle($request, $response);
             // save response
             $resp = array('headers' => $this->getCacheHeaders($response), 'body' => Util::toString($response->getBody()));
             $item->set($resp, $this->ttl);
             $this->cache->save($item);
         }
     } else {
         // if we have no key we can not use a cache
         $filterChain->handle($request, $response);
     }
 }