Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function canUseResponseFromCache(RequestInterface $request, ResponseInterface $cachedResponse = null)
 {
     if ($cachedResponse !== null && $request->getMethod() == 'GET' && !$request->isNoCache()) {
         return $this->isResponseFreshEnoughForTheClient($request, $cachedResponse);
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  *
  * @return array
  */
 protected function getLogData(RequestInterface $request, ResponseInterface $response = null)
 {
     $time = $this->stopwatch->stop(self::STOPWATCH_EVENT)->getDuration();
     $uagent = $request->getHeader('User-Agent', '-');
     $uagent = $uagent[0];
     $xcache = $response && $response->hasHeaderWithValue('x-cache', 'HIT') ? 'HIT' : 'MISS';
     $postDumpLimit = 200;
     $postData = json_encode($request->getPostParams());
     if (strlen($postData) > $postDumpLimit) {
         $postData = substr($postData, 0, $postDumpLimit) . '...';
     }
     $data = array();
     $data[] = $xcache;
     $data[] = bcdiv($time, 1000, 4);
     // milliseconds
     $data[] = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1';
     // @todo ip is always set to 127.0.0.1 due to broken request object
     $data[] = $request->getMethod();
     $data[] = $request->getUri();
     $data[] = $response ? $response->getStatusCode() : '-';
     // bytes
     $data[] = $response ? $response->getLength() : '-';
     // bytes
     $data[] = sprintf('"%s"', $uagent);
     $data[] = $postData;
     return $data;
 }
Exemplo n.º 3
0
 /**
  * @param RequestInterface $request
  *
  * @return \GuzzleHttp\Message\RequestInterface
  */
 protected function createGuzzleRequestFromRequest(RequestInterface $request)
 {
     $headers = array();
     foreach ($request->getHeaders() as $headerName => $headerValue) {
         $headers[$headerName] = $headerValue[0];
     }
     $headers['X-Forwarded-For'] = $request->getClientIp();
     $headers['X-Forwarded-Proto'] = $request->getScheme();
     if (isset($headers['cookie'])) {
         unset($headers['cookie']);
     }
     // see http://guzzle.readthedocs.org/en/latest/clients.html#request-options
     $guzzleRequest = $this->client->createRequest($request->getMethod(), $request->getUri(), array('headers' => $headers, 'body' => $request->getBody(), 'query' => $request->getQueryParams(), 'cookies' => $request->getCookies(), 'exceptions' => false, 'decode_content' => true));
     return $guzzleRequest;
 }