function its_middleware_adds_the_header_to_the_request(RequestIdentifierResolver $resolver, RequestInterface $request)
 {
     $identifier = StringRequestIdentifier::fromString('1234');
     $resolver->get()->shouldBeCalled()->willReturn($identifier);
     $request->withAddedHeader('X-Request-Id', '1234')->shouldBeCalled();
     $middlewareFactory = $this->create();
     $middleware = $middlewareFactory(function () {
     });
     $middleware($request, []);
 }
 /**
  * @param string $header
  * @param string|\string[] $value
  * @return \Psr\Http\Message\MessageInterface
  */
 public function withAddedHeader($header, $value)
 {
     $this->request = $this->request->withAddedHeader($header, $value);
     return $this;
 }
Example #3
0
 /**
  * Sign amazon request.
  *
  * @param RequestInterface $request
  * @param array            $packedCommands Headers generated based on request commands, see
  *                                         packCommands() method for more information.
  * @return RequestInterface
  */
 private function signRequest(RequestInterface $request, array $packedCommands = [])
 {
     $signature = [$request->getMethod(), $request->getHeaderLine('Content-MD5'), $request->getHeaderLine('Content-Type'), $request->getHeaderLine('Date')];
     $normalizedCommands = [];
     foreach ($packedCommands as $command => $value) {
         if (!empty($value)) {
             $normalizedCommands[] = strtolower($command) . ':' . $value;
         }
     }
     if ($normalizedCommands) {
         sort($normalizedCommands);
         $signature[] = join("\n", $normalizedCommands);
     }
     $signature[] = $request->getUri()->getPath();
     return $request->withAddedHeader('Authorization', 'AWS ' . $this->options['accessKey'] . ':' . base64_encode(hash_hmac('sha1', join("\n", $signature), $this->options['secretKey'], true)));
 }
Example #4
0
 /**
  * @param RequestInterface $request
  *
  * @return RequestInterface
  */
 public function addAuthentificationInfo(RequestInterface $request)
 {
     return $request->withAddedHeader($this->header_name, $this->value);
 }
Example #5
0
 public function withAddedHeader($name, $value)
 {
     $new = clone $this;
     $new->request = $this->request->withAddedHeader($name, $value);
     return $new;
 }