Exemplo n.º 1
0
 /**
  * @inheritDoc
  */
 public function format(RequestInterface $request, ResponseInterface $response = null, \Exception $error = null, array $customData = [])
 {
     if (in_array($request->getPath(), $this->paths)) {
         $customData = array_merge(['url' => $this->mask((string) $request->getUrl()), 'resource' => $this->mask($request->getResource()), 'request' => $this->mask((string) $request), 'response' => $this->mask((string) $response), 'res_body' => $response ? $this->mask((string) $response) : 'NULL', 'req_body' => $this->mask((string) $request->getBody())], $customData);
     }
     return parent::format($request, $response, $error, $customData);
 }
Exemplo n.º 2
0
 /**
  * Creates a Ring request from a request object.
  *
  * This function does not hook up the "then" and "progress" events that
  * would be required for actually sending a Guzzle request through a
  * RingPHP handler.
  *
  * @param RequestInterface $request Request to convert.
  *
  * @return array Converted Guzzle Ring request.
  */
 public static function createRingRequest(RequestInterface $request)
 {
     $options = $request->getConfig()->toArray();
     $url = $request->getUrl();
     // No need to calculate the query string twice (in URL and query).
     $qs = ($pos = strpos($url, '?')) ? substr($url, $pos + 1) : null;
     return ['scheme' => $request->getScheme(), 'http_method' => $request->getMethod(), 'url' => $url, 'uri' => $request->getPath(), 'headers' => $request->getHeaders(), 'body' => $request->getBody(), 'version' => $request->getProtocolVersion(), 'client' => $options, 'query_string' => $qs, 'future' => isset($options['future']) ? $options['future'] : false];
 }
Exemplo n.º 3
0
 /**
  * @param RequestInterface $actual
  * @param RequestInterface $expected
  * @throws FailedRequestExpectationException
  */
 public static function checkRequest(RequestInterface $actual, RequestInterface $expected)
 {
     self::checkIsEqual($actual->getHost(), $expected->getHost(), 'host');
     self::checkIsEqual($actual->getPath(), $expected->getPath(), 'url path');
     self::checkIsEqual($actual->getMethod(), $expected->getMethod(), 'http method');
     self::checkRequestQuery($actual, $expected);
     self::checkContentType($actual, $expected);
     self::checkRequestBody($actual, $expected);
 }
 /**
  * @param RequestInterface $request
  * @return array ['query' => ..., 'request' => ...]
  */
 protected function getRequestAndQuery(RequestInterface $request)
 {
     $query = [];
     foreach ($request->getQuery() as $param => $val) {
         $query[$param] = $val;
     }
     $requestInfo = ['url' => $request->getUrl(), 'path' => $request->getPath(), 'queryString' => (string) $request->getQuery(), 'method' => $request->getMethod(), 'hostname' => $request->getHost(), 'port' => $request->getPort(), 'resource' => $request->getResource()];
     return ['query' => $query, 'request' => $requestInfo];
 }
Exemplo n.º 5
0
 public function __construct(RequestInterface $pRequest)
 {
     /** url parsing "formula" for resource */
     list(, $subscription, $format, , $season, $week) = explode('/', $pRequest->getPath());
     $file_partial = __DIR__ . '/' . implode('.', [$subscription, $format, $season, $week]);
     $headers = (include $file_partial . '.header.php');
     $response_code = explode(' ', $headers[0])[1];
     $mocked_response = file_get_contents($file_partial . '.body.' . $format);
     $stream = Stream\Stream::factory($mocked_response);
     parent::__construct($response_code, $headers, $stream);
 }
Exemplo n.º 6
0
 public function addCookieHeader(RequestInterface $request)
 {
     $values = array();
     $scheme = $request->getScheme();
     $host = $request->getHost();
     $path = $request->getPath();
     foreach ($this->cookies as $cookie) {
         if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
             $values[] = $cookie->getName() . '=' . self::getCookieValue($cookie->getValue());
         }
     }
     if ($values) {
         $request->setHeader('Cookie', implode('; ', $values));
     }
 }
Exemplo n.º 7
0
 /**
  * @param RequestInterface $request
  */
 protected function extractCookiesArgument(RequestInterface $request)
 {
     $listeners = $request->getEmitter()->listeners('before');
     foreach ($listeners as $listener) {
         if ($listener[0] instanceof Cookie) {
             $values = [];
             $scheme = $request->getScheme();
             $host = $request->getHost();
             $path = $request->getPath();
             /** @var SetCookie $cookie */
             foreach ($listener[0]->getCookieJar() as $cookie) {
                 if ($cookie->matchesPath($path) && $cookie->matchesDomain($host) && !$cookie->isExpired() && (!$cookie->getSecure() || $scheme == 'https')) {
                     $values[] = $cookie->getName() . '=' . CookieJar::getCookieValue($cookie->getValue());
                 }
             }
             if ($values) {
                 $this->addOption('b', escapeshellarg(implode('; ', $values)));
             }
         }
     }
 }
 /**
  * Generate the hash based on the key, path and session
  *
  * @param  RequestInterface $request
  * @param  Collection $config
  * @return string
  */
 protected function getHash(RequestInterface $request, Collection $config)
 {
     // Remove the /api from the path to get the correct path
     $path = str_replace('/api', '', $request->getPath());
     return md5($config['key'] . '#' . $path . '#' . $config['session_id']);
 }
 /**
  * Asserts response match with the response schema.
  *
  * @param ResponseInterface $response
  * @param RequestInterface $request
  * @param SchemaManager $schemaManager
  * @param string $message
  */
 public function assertResponseAndRequestMatch(ResponseInterface $response, RequestInterface $request, SchemaManager $schemaManager, $message = '')
 {
     $this->assertResponseMatch($response, $schemaManager, $request->getPath(), $request->getMethod(), $message);
 }
Exemplo n.º 10
0
 /**
  * @internal Create the canonical representation of a request
  * @param RequestInterface $request Request to canonicalize
  * @param string           $payload Hash of the request payload
  * @return array Returns an array of context information
  */
 private function createContext(RequestInterface $request, $payload)
 {
     static $signable = ['host' => true, 'date' => true, 'content-md5' => true];
     // Normalize the path as required by SigV4 and ensure it's absolute
     $canon = $request->getMethod() . "\n" . '/' . ltrim($request->getPath(), '/') . "\n" . $this->getCanonicalizedQuery($request) . "\n";
     $canonHeaders = [];
     // Always include the "host", "date", and "x-amz-" headers.
     foreach ($request->getHeaders() as $key => $values) {
         $key = strtolower($key);
         if (isset($signable[$key]) || substr($key, 0, 6) === 'x-amz-') {
             if (count($values) == 1) {
                 $values = $values[0];
             } else {
                 sort($values);
                 $values = implode(',', $values);
             }
             $canonHeaders[$key] = $key . ':' . preg_replace('/\\s+/', ' ', $values);
         }
     }
     ksort($canonHeaders);
     $signedHeadersString = implode(';', array_keys($canonHeaders));
     $canon .= implode("\n", $canonHeaders) . "\n\n" . $signedHeadersString . "\n" . $payload;
     return ['creq' => $canon, 'headers' => $signedHeadersString];
 }
Exemplo n.º 11
0
 /**
  * Collect & sanitize data about a Guzzle request.
  *
  * @param RequestInterface $request Guzzle request.
  * @return array
  */
 private function collectRequest(RequestInterface $request)
 {
     $query = $request->getQuery();
     return ['headers' => $request->getHeaders(), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHost(), 'path' => $request->getPath(), 'query' => (string) $query, 'queryParams' => $query->toArray(), 'body' => (string) $request->getBody()];
 }
Exemplo n.º 12
0
 /**
  * @param RequestInterface $request
  *
  * @return string
  */
 private function getName(RequestInterface $request)
 {
     return $request->getMethod() . ' ' . $request->getPath();
 }