Пример #1
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;
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function isAllowed(RequestInterface $request)
 {
     if (!empty($this->allowedIps)) {
         $clientIp = $this->normalize($request->getClientIp());
         if (!in_array($clientIp, $this->allowedIps)) {
             return false;
         }
     }
     if (!empty($this->allowedDomains)) {
         $domain = $this->normalize($request->getHost());
         if (!in_array($domain, $this->allowedDomains)) {
             return false;
         }
     }
     return true;
 }