Ejemplo n.º 1
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 puzzle_message_RequestInterface  $request
  * @param puzzle_message_ResponseInterface $response
  *
  * @return puzzle_message_RequestInterface Returns a new redirect request
  * @throws puzzle_exception_CouldNotRewindStreamException If the body cannot be rewound.
  */
 private function createRedirectRequest(puzzle_message_RequestInterface $request, puzzle_message_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 = puzzle_Url::fromString($request->getUrl());
         $url->setUsername(null)->setPassword(null);
         $redirectRequest->setHeader('Referer', (string) $url);
     }
     return $redirectRequest;
 }
Ejemplo n.º 2
0
 private function add_proxy(puzzle_message_RequestInterface $request, &$options, $value, &$params)
 {
     if (!is_array($value)) {
         $options['http']['proxy'] = $value;
     } else {
         $scheme = $request->getScheme();
         if (isset($value[$scheme])) {
             $options['http']['proxy'] = $value[$scheme];
         }
     }
 }
Ejemplo n.º 3
0
 private function add_proxy(puzzle_message_RequestInterface $request, puzzle_adapter_curl_RequestMediator $mediator, $value)
 {
     if (!is_array($value)) {
         $this->_closure_handleOptions[CURLOPT_PROXY] = $value;
     } else {
         $scheme = $request->getScheme();
         if (isset($value[$scheme])) {
             $this->_closure_handleOptions[CURLOPT_PROXY] = $value[$scheme];
         }
     }
 }
Ejemplo n.º 4
0
 public function addCookieHeader(puzzle_message_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));
     }
 }