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()))); } }
protected function fill() { if (!$this->isFilled) { $this->data = Util::toString($this->source); $this->isFilled = true; } }
protected function getBodyAsString(RequestInterface $request) { $body = Util::toString($request->getBody()); if (empty($body)) { $body = null; } return $body; }
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); } } }
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); } }