public function send(puzzle_adapter_TransactionInterface $transaction) { // HTTP/1.1 streams using the PHP stream wrapper require a // Connection: close header. Setting here so that it is added before // emitting the request.before_send event. $request = $transaction->getRequest(); if ($request->getProtocolVersion() == '1.1' && !$request->hasHeader('Connection')) { $transaction->getRequest()->setHeader('Connection', 'close'); } puzzle_event_RequestEvents::emitBefore($transaction); if (!$transaction->getResponse()) { $this->createResponse($transaction); puzzle_event_RequestEvents::emitComplete($transaction); } return $transaction->getResponse(); }
public function send(puzzle_adapter_TransactionInterface $transaction) { puzzle_event_RequestEvents::emitBefore($transaction); if (!$transaction->getResponse()) { // Read the request body if it is present if ($transaction->getRequest()->getBody()) { $transaction->getRequest()->getBody()->__toString(); } $response = is_callable($this->response) ? call_user_func($this->response, $transaction) : $this->response; if (!$response instanceof puzzle_message_ResponseInterface) { throw new RuntimeException('Invalid mocked response'); } $transaction->setResponse($response); puzzle_event_RequestEvents::emitHeaders($transaction); puzzle_event_RequestEvents::emitComplete($transaction); } return $transaction->getResponse(); }
public function send(puzzle_adapter_TransactionInterface $transaction) { puzzle_event_RequestEvents::emitBefore($transaction); if ($response = $transaction->getResponse()) { return $response; } $factory = $this->curlFactory; $handle = $factory->__invoke($transaction, $this->messageFactory, $this->checkoutEasyHandle()); curl_exec($handle); $info = curl_getinfo($handle); $info['curl_result'] = curl_errno($handle); if ($info['curl_result']) { $this->handleError($transaction, $info, $handle); } else { $this->releaseEasyHandle($handle); puzzle_event_RequestEvents::emitComplete($transaction, $info); } return $transaction->getResponse(); }
private function addHandle(puzzle_adapter_TransactionInterface $transaction, puzzle_adapter_curl_BatchContext $context) { try { puzzle_event_RequestEvents::emitBefore($transaction); // Only transfer if the request was not intercepted if (!$transaction->getResponse()) { $factory = $this->curlFactory; $context->addTransaction($transaction, call_user_func_array(array($factory, '__invoke'), array($transaction, $this->messageFactory))); } } catch (puzzle_exception_RequestException $e) { $this->throwException($e, $context); } }
public function testThrowsUnInterceptedErrors() { $this->_closure_testThrowsUnInterceptedErrors_ex = new Exception('Foo'); $client = new puzzle_Client(); $request = new puzzle_message_Request('GET', '/'); $t = new puzzle_adapter_Transaction($client, $request); $this->_closure_testThrowsUnInterceptedErrors_errCalled = 0; $request->getEmitter()->on('before', array($this, '__callback_testThrowsUnInterceptedErrors')); $request->getEmitter()->on('error', array($this, '__callback_testThrowsUnInterceptedErrors_2')); try { puzzle_event_RequestEvents::emitBefore($t); $this->fail('Did not throw'); } catch (puzzle_exception_RequestException $e) { $this->assertEquals(1, $this->_closure_testThrowsUnInterceptedErrors_errCalled); } }