public function testHasValues() { $c = new puzzle_Client(); $r = new puzzle_message_Request('GET', '/'); $res = new puzzle_message_Response(200); $t = new puzzle_adapter_Transaction($c, $r); $e = new puzzle_event_CompleteEvent($t); $e->intercept($res); $this->assertTrue($e->isPropagationStopped()); $this->assertSame($res, $e->getResponse()); }
/** * 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); } }
public function __callback_testDispatchesAfterSendEvent(puzzle_event_CompleteEvent $e) { $this->_closure_testDispatchesAfterSendEvent_ev = $e; $e->intercept(new puzzle_message_Response(200, array('Foo' => 'bar'))); }