Esempio n. 1
0
 /**
  * Throw a puzzle_exception_RequestException on an HTTP protocol error
  *
  * @param puzzle_event_CompleteEvent $event Emitted event
  * @throws puzzle_exception_RequestException
  */
 public function onComplete(puzzle_event_CompleteEvent $event)
 {
     $code = (string) $event->getResponse()->getStatusCode();
     // Throw an exception for an unsuccessful response
     if ($code[0] === '4' || $code[0] === '5') {
         throw puzzle_exception_RequestException::create($event->getRequest(), $event->getResponse());
     }
 }
Esempio n. 2
0
 /**
  * Called when a request receives a redirect response
  *
  * @param puzzle_event_CompleteEvent $event Event emitted
  * @throws puzzle_exception_TooManyRedirectsException
  */
 public function onComplete(puzzle_event_CompleteEvent $event)
 {
     $response = $event->getResponse();
     if (substr($response->getStatusCode(), 0, 1) != '3' || !$response->hasHeader('Location')) {
         return;
     }
     $redirectCount = 0;
     $redirectRequest = $event->getRequest();
     $redirectResponse = $response;
     $max = $redirectRequest->getConfig()->getPath('redirect/max') ? $redirectRequest->getConfig()->getPath('redirect/max') : 5;
     do {
         if (++$redirectCount > $max) {
             throw new puzzle_exception_TooManyRedirectsException("Will not follow more than {$redirectCount} redirects", $redirectRequest);
         }
         $redirectRequest = $this->createRedirectRequest($redirectRequest, $redirectResponse);
         $redirectResponse = $event->getClient()->send($redirectRequest);
     } while (substr($redirectResponse->getStatusCode(), 0, 1) == '3' && $redirectResponse->hasHeader('Location'));
     if ($redirectResponse !== $response) {
         $event->intercept($redirectResponse);
     }
 }
Esempio n. 3
0
 public function __callback_testThrowsUnhandledErrors(puzzle_event_CompleteEvent $e)
 {
     throw new puzzle_exception_RequestException('foo', $e->getRequest());
 }
Esempio n. 4
0
 public function __callback_testDispatchesErrorEventAndRecovers_1(puzzle_event_CompleteEvent $e)
 {
     throw new puzzle_exception_RequestException('Foo', $e->getRequest());
 }
Esempio n. 5
0
 public function onComplete(puzzle_event_CompleteEvent $event)
 {
     $this->add($event->getRequest(), $event->getResponse());
 }
Esempio n. 6
0
 public function __callback_testThrowsAndReleasesWhenErrorDuringCompleteEvent(puzzle_event_CompleteEvent $e)
 {
     throw new puzzle_exception_RequestException('foo', $e->getRequest());
 }
Esempio n. 7
0
 public function onComplete(puzzle_event_CompleteEvent $event)
 {
     $this->cookieJar->extractCookies($event->getRequest(), $event->getResponse());
 }