Example #1
0
 /**
  * Creates a Ring request from a request object.
  *
  * This function does not hook up the "then" and "progress" events that
  * would be required for actually sending a Guzzle request through a
  * RingPHP handler.
  *
  * @param RequestInterface $request Request to convert.
  *
  * @return array Converted Guzzle Ring request.
  */
 public static function createRingRequest(RequestInterface $request)
 {
     $options = $request->getConfig()->toArray();
     $url = $request->getUrl();
     // No need to calculate the query string twice (in URL and query).
     $qs = ($pos = strpos($url, '?')) ? substr($url, $pos + 1) : null;
     return ['scheme' => $request->getScheme(), 'http_method' => $request->getMethod(), 'url' => $url, 'uri' => $request->getPath(), 'headers' => $request->getHeaders(), 'body' => $request->getBody(), 'version' => $request->getProtocolVersion(), 'client' => $options, 'query_string' => $qs, 'future' => isset($options['future']) ? $options['future'] : false];
 }
 private function add_proxy(RequestInterface $request, &$options, $value, &$params)
 {
     if (!is_array($value)) {
         $options['http']['proxy'] = $value;
         $options['http']['request_fulluri'] = true;
     } else {
         $scheme = $request->getScheme();
         if (isset($value[$scheme])) {
             $options['http']['proxy'] = $value[$scheme];
             $options['http']['request_fulluri'] = true;
         }
     }
 }
 private function add_proxy(RequestInterface $request, RequestMediator $mediator, &$options, $value)
 {
     if (!is_array($value)) {
         $options[CURLOPT_PROXY] = $value;
     } else {
         $scheme = $request->getScheme();
         if (isset($value[$scheme])) {
             $options[CURLOPT_PROXY] = $value[$scheme];
         }
     }
 }
Example #4
0
 public function addCookieHeader(RequestInterface $request)
 {
     $values = array();
     $scheme = $request->getScheme();
     $host = $request->getHost();
     $path = $request->getPath();
     foreach ($this->cookies as $cookie) {
         if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
             $values[] = $cookie->getName() . '=' . self::getCookieValue($cookie->getValue());
         }
     }
     if ($values) {
         $request->setHeader('Cookie', implode('; ', $values));
     }
 }
Example #5
0
 /**
  * @param RequestInterface $request
  */
 protected function extractCookiesArgument(RequestInterface $request)
 {
     $listeners = $request->getEmitter()->listeners('before');
     foreach ($listeners as $listener) {
         if ($listener[0] instanceof Cookie) {
             $values = [];
             $scheme = $request->getScheme();
             $host = $request->getHost();
             $path = $request->getPath();
             /** @var SetCookie $cookie */
             foreach ($listener[0]->getCookieJar() as $cookie) {
                 if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
                     $values[] = $cookie->getName() . '=' . CookieJar::getCookieValue($cookie->getValue());
                 }
             }
             if ($values) {
                 $this->addOption('b', escapeshellarg(implode('; ', $values)));
             }
         }
     }
 }
Example #6
0
 /**
  * Create a redirect request for a specific request object
  *
  * Takes into account strict RFC compliant redirection (e.g. redirect POST
  * with POST) vs doing what most clients do (e.g. redirect POST with GET).
  *
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  *
  * @return RequestInterface Returns a new redirect request
  * @throws CouldNotRewindStreamException If the body cannot be rewound.
  */
 private function createRedirectRequest(RequestInterface $request, ResponseInterface $response)
 {
     $config = $request->getConfig();
     // Use a GET request if this is an entity enclosing request and we are
     // not forcing RFC compliance, but rather emulating what all browsers
     // would do. Be sure to disable redirects on the clone.
     $redirectRequest = clone $request;
     $redirectRequest->getEmitter()->detach($this);
     $statusCode = $response->getStatusCode();
     if ($statusCode == 303 || $statusCode <= 302 && $request->getBody() && !$config->getPath('redirect/strict')) {
         $redirectRequest->setMethod('GET');
         $redirectRequest->setBody(null);
     }
     $this->setRedirectUrl($redirectRequest, $response);
     $this->rewindEntityBody($redirectRequest);
     // Add the Referer header if it is told to do so and only
     // add the header if we are not redirecting from https to http.
     if ($config->getPath('redirect/referer') && ($redirectRequest->getScheme() == 'https' || $redirectRequest->getScheme() == $request->getScheme())) {
         $url = Url::fromString($request->getUrl());
         $url->setUsername(null)->setPassword(null);
         $redirectRequest->setHeader('Referer', (string) $url);
     }
     return $redirectRequest;
 }
 /**
  * Collect & sanitize data about a Guzzle request.
  *
  * @param RequestInterface $request Guzzle request.
  * @return array
  */
 private function collectRequest(RequestInterface $request)
 {
     $query = $request->getQuery();
     return ['headers' => $request->getHeaders(), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHost(), 'path' => $request->getPath(), 'query' => (string) $query, 'queryParams' => $query->toArray(), 'body' => (string) $request->getBody()];
 }