public function printResult() { echo sprintf('%s %s : %s calls', strtoupper($this->request->getMethod()), $this->request->getUrl(), $this->nbCalls) . PHP_EOL; foreach ($this->httpTimeDataCollector->getIterator() as $httpTimeResult) { echo sprintf('total time = %s ms', $httpTimeResult) . PHP_EOL; } echo '--- statistics ---' . PHP_EOL; echo sprintf('results filter on %s percentile', $this->httpTimeDataCollector->getPercentile()) . PHP_EOL; echo sprintf('min/avg/max = %s/%s/%s ms', $this->httpTimeDataCollector->getMinTime(), $this->httpTimeDataCollector->getAverageTime(), $this->httpTimeDataCollector->getMaxTime()) . PHP_EOL; }
/** * Sign the current request for write operations * * @param Request $request The current request */ private function addAuthenticationHeaders(Request $request) { $client = $request->getClient(); // Get a GMT/UTC timestamp $timestamp = gmdate('Y-m-d\\TH:i:s\\Z'); // Build the data to base the hash on $data = $request->getMethod() . '|' . $request->getUrl() . '|' . $client->getConfig('publicKey') . '|' . $timestamp; // Generate signature $signature = hash_hmac('sha256', $data, $client->getConfig('privateKey')); // Add relevant request headers (overwriting once that might already exist) $request->setHeader('X-Imbo-Authenticate-Signature', $signature); $request->setHeader('X-Imbo-Authenticate-Timestamp', $timestamp); }
public function fromRequest(Request $request, $secretKey) { $method = strtolower($request->getMethod()); switch ($method) { case 'post': case 'patch': case 'put': case 'delete': $body = (string) $request->getBody(); break; default: $body = $request->getQuery(true); } return $this->generate($body, $secretKey); }
/** * Function to send the request to the remote API * * @return \Trucker\Responses\Response */ public function sendRequest() { try { $response = $this->request->send(); } catch (\Guzzle\Http\Exception\BadResponseException $e) { $response = $e->getResponse(); } if (Config::get('request.debug', false)) { echo 'Request Method: ' . $this->request->getMethod() . "\n"; echo "Body: " . $response->getBody() . "\n"; echo "Status Code: " . $response->getStatusCode() . "\n"; echo "URL: " . $this->request->getUrl() . "\n\n"; } return $this->app->make('trucker.response')->newInstance($this->app, $response); }
/** * @param \Guzzle\Http\Message\Request $request */ public function signRequest(Request $request) { $url = $request->getPath(); if ('POST' == $request->getMethod() && $request instanceof EntityEnclosingRequest) { $body = (string) $request->getBody(); $hash = $this->signature->generate($body); } else { $url .= '?' . $request->getQuery(); $hash = $this->signature->generate($url); } $request->addCookie('acquia_solr_time', $this->signature->getRequestTime()); $request->addCookie('acquia_solr_nonce', $this->signature->getNonce()); $request->addCookie('acquia_solr_hmac', $hash . ';'); // The timestamp should be current for each request. $this->signature->unsetRequestTime(); }
private function send(Request $request) { try { $this->logger and $this->logger->debug(sprintf('%s "%s"', $request->getMethod(), $request->getUrl())); $this->logger and $this->logger->debug(sprintf("Request:\n%s", (string) $request)); $response = $this->client->send($request); $this->logger and $this->logger->debug(sprintf("Response:\n%s", (string) $response)); return $response; } catch (ClientErrorResponseException $e) { $this->logException($e); $statusCode = $e->getResponse()->getStatusCode(); $reasonPhrase = $e->getResponse()->getReasonPhrase(); $message = sprintf('The request is not valid (status code: "%d", reason phrase: "%s").', $statusCode, $reasonPhrase); throw new ApiClientException($message, 0, $e); } catch (BadResponseException $e) { $this->logException($e); throw new ApiServerException('Something went wrong with upstream.', 0, $e); } }
/** * @AfterScenario */ public function printLastResponseOnError(BaseScenarioEvent $scenarioEvent) { if ($scenarioEvent->getResult() == StepEvent::FAILED) { if ($this->response) { $body = $this->getResponse()->getBody(true); // could we even ask them if they want to print out the error? // or do it based on verbosity // print some debug details $this->printDebug(''); $this->printDebug('<error>Failure!</error> when making the following request:'); $this->printDebug(sprintf('<comment>%s</comment>: <info>%s</info>', $this->lastRequest->getMethod(), $this->lastRequest->getUrl()) . "\n"); if ($this->response->isContentType('application/json') || $this->response->isContentType('+json')) { $data = json_decode($body); if ($data === null) { // invalid JSON! $this->printDebug($body); } else { // valid JSON, print it pretty $this->printDebug(json_encode($data, JSON_PRETTY_PRINT)); } } else { // the response is HTML - see if we should print all of it or some of it $isValidHtml = strpos($body, '</body>') !== false; if ($this->useFancyExceptionReporting && $isValidHtml) { $this->printDebug('<error>Failure!</error> Below is a summary of the HTML response from the server.'); // finds the h1 and h2 tags and prints them only $crawler = new Crawler($body); foreach ($crawler->filter('h1, h2')->extract(array('_text')) as $header) { $this->printDebug(sprintf(' ' . $header)); } } else { $this->printDebug($body); } } } } }
/** * @param Request $request * @param string $body */ private function processSuccessfulRequest(Request $request, $body) { $response = $request->getResponse(); $headers = $request->getHeaders()->getAll(); $responseBody = $response->getBody(true); $status = $response->getStatusCode(); $this->lastRequest['response']['body'] = $responseBody; $this->lastRequest['response']['status'] = $status; $this->logRequestSuccess($request->getMethod(), $request->getUrl(), $body, $headers, $status, $responseBody, $response->getInfo('total_time')); }
/** * @covers Guzzle\Http\Message\Request::getMethod */ public function testRequestHasMethod() { $this->assertEquals('GET', $this->request->getMethod()); }
/** * {@inheritDoc} */ public function getMethod() { return $this->request->getMethod(); }