/**
  * {@inheritdoc}
  */
 protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
 {
     try {
         $this->eventDispatcher->dispatch(Events::REQUEST_CREATED, $requestCreatedEvent = new RequestCreatedEvent($this, $internalRequest));
         $response = parent::doSendInternalRequest($requestCreatedEvent->getRequest());
         $this->eventDispatcher->dispatch(Events::REQUEST_SENT, $requestSentEvent = new RequestSentEvent($this, $requestCreatedEvent->getRequest(), $response));
         if ($requestSentEvent->hasException()) {
             throw $requestSentEvent->getException();
         }
         $response = $requestSentEvent->getResponse();
     } catch (HttpAdapterException $e) {
         $e->setRequest($internalRequest);
         $e->setResponse(isset($response) ? $response : null);
         $this->eventDispatcher->dispatch(Events::REQUEST_ERRORED, $exceptionEvent = new RequestErroredEvent($this, $e));
         if ($exceptionEvent->hasResponse()) {
             return $exceptionEvent->getResponse();
         }
         throw $exceptionEvent->getException();
     }
     return $response;
 }
Exemplo n.º 2
0
 /**
  * On request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestSentEvent $event The request sent event.
  */
 public function onRequestSent(RequestSentEvent $event)
 {
     $this->cookieJar->extract($event->getRequest(), $event->getResponse());
 }
 /**
  * On request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestSentEvent $event The request sent event.
  */
 public function onRequestSent(RequestSentEvent $event)
 {
     if (!$this->statusCode->validate($event->getResponse())) {
         $event->setException($this->createStatusCodeException($event->getResponse(), $event->getRequest(), $event->getHttpAdapter()));
     }
 }
Exemplo n.º 4
0
 /**
  * On request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestSentEvent $event The request sent event.
  */
 public function onRequestSent(RequestSentEvent $event)
 {
     $event->setRequest($this->debug($event->getHttpAdapter(), $event->getRequest(), $event->getResponse()));
 }
Exemplo n.º 5
0
 /**
  * On request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestSentEvent $event The request sent event.
  */
 public function onRequestSent(RequestSentEvent $event)
 {
     $event->setRequest($this->record($event->getRequest(), $event->getResponse()));
 }
Exemplo n.º 6
0
 /**
  * On request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestSentEvent $event The request sent event.
  */
 public function onRequestSent(RequestSentEvent $event)
 {
     try {
         $redirectRequest = $this->redirect->createRedirectRequest($event->getResponse(), $event->getRequest(), $event->getHttpAdapter());
     } catch (HttpAdapterException $e) {
         $event->setException($e);
         return;
     }
     if ($redirectRequest === false) {
         $event->setResponse($this->redirect->prepareResponse($event->getResponse(), $event->getRequest()));
         return;
     }
     try {
         $event->setResponse($event->getHttpAdapter()->sendRequest($redirectRequest));
     } catch (HttpAdapterException $e) {
         $event->setException($e);
     }
 }
Exemplo n.º 7
0
 /**
  * On request sent event.
  *
  * @param \Ivory\HttpAdapter\Event\RequestSentEvent $event The event.
  */
 public function onRequestSent(RequestSentEvent $event)
 {
     $this->stopwatch->stop($this->getStopwatchName($event->getHttpAdapter(), $event->getRequest()));
 }
 /**
  * On post send event.
  *
  * We reach this event when the request has not been intercepted.
  *
  * @param RequestSentEvent $event The post send event.
  */
 public function onPostSend(RequestSentEvent $event)
 {
     if (!$this->isRecording) {
         return;
     }
     $request = $event->getRequest();
     if (!$this->currentTape->hasTrackForRequest($request)) {
         return;
     }
     $track = $this->currentTape->getTrackForRequest($request);
     $this->currentTape->finishRecording($track, $event->getResponse(), $event->hasException() ? $event->getException() : null);
 }