getRequestTarget example


        $request->headers->set(' X-Broken', 'abc');

        $psrRequest = $factory->createRequest($request);

        $this->assertSame('Content', $psrRequest->getBody()->__toString());

        $queryParams = $psrRequest->getQueryParams();
        $this->assertSame('1', $queryParams['foo']);
        $this->assertSame('42', $queryParams['bar']['baz']);

        $requestTarget = $psrRequest->getRequestTarget();
        $this->assertSame('/testCreateRequest?bar[baz]=42&foo=1', urldecode($requestTarget));

        $parsedBody = $psrRequest->getParsedBody();
        $this->assertSame('Kévin Dunglas', $parsedBody['twitter']['@dunglas']);
        $this->assertSame('Les-Tilleuls.coop', $parsedBody['twitter']['@coopTilleuls']);
        $this->assertSame('2', $parsedBody['baz']);

        $attributes = $psrRequest->getAttributes();
        $this->assertSame($stdClass$attributes['a1']);
        $this->assertSame('bar', $attributes['a2']['foo']);

        
yield strtolower($key) => $value;
                }
            };
            $this->assertEquals($request->getAttributes()$finalRequest->getAttributes());
            $this->assertEquals($request->getCookieParams()$finalRequest->getCookieParams());
            $this->assertEquals((array) $request->getParsedBody()(array) $finalRequest->getParsedBody());
            $this->assertEquals($request->getQueryParams()$finalRequest->getQueryParams());
            // PSR7 does not define a "withServerParams" so this is impossible to implement without knowing the PSR7 implementation.             // $this->assertEquals($request->getServerParams(), $finalRequest->getServerParams());             $this->assertEquals($request->getUploadedFiles()$finalRequest->getUploadedFiles());
            $this->assertEquals($request->getMethod()$finalRequest->getMethod());
            $this->assertEquals($request->getRequestTarget()$finalRequest->getRequestTarget());
            $this->assertEquals((string) $request->getUri()(string) $finalRequest->getUri());
            $this->assertEquals((string) $request->getBody()(string) $finalRequest->getBody());
            $this->assertEquals($strToLower($request->getHeaders())$strToLower($finalRequest->getHeaders()));
            $this->assertEquals($request->getProtocolVersion()$finalRequest->getProtocolVersion());
        } else {
            $this->fail('$finalRequest must be an instance of PSR7 or a HTTPFoundation request');
        }
    }

    public static function requestProvider(): array
    {
        
final class Message
{
    /** * Returns the string representation of an HTTP message. * * @param MessageInterface $message Message to convert to a string. */
    public static function toString(MessageInterface $message): string
    {
        if ($message instanceof RequestInterface) {
            $msg = trim($message->getMethod().' '
                    .$message->getRequestTarget())
                .' HTTP/'.$message->getProtocolVersion();
            if (!$message->hasHeader('host')) {
                $msg .= "\r\nHost: ".$message->getUri()->getHost();
            }
        } elseif ($message instanceof ResponseInterface) {
            $msg = 'HTTP/'.$message->getProtocolVersion().' '
                .$message->getStatusCode().' '
                .$message->getReasonPhrase();
        } else {
            throw new \InvalidArgumentException('Unknown message type');
        }

        
$result = '';
                switch ($matches[1]) {
                    case 'request':
                        $result = Psr7\Message::toString($request);
                        break;
                    case 'response':
                        $result = $response ? Psr7\Message::toString($response) : '';
                        break;
                    case 'req_headers':
                        $result = \trim($request->getMethod()
                                .' '.$request->getRequestTarget())
                            .' HTTP/'.$request->getProtocolVersion()."\r\n"
                            .$this->headers($request);
                        break;
                    case 'res_headers':
                        $result = $response ?
                            \sprintf(
                                'HTTP/%s %d %s',
                                $response->getProtocolVersion(),
                                $response->getStatusCode(),
                                $response->getReasonPhrase()
                            )."\r\n".$this->headers($response)
                            :
3,
            $this->createMock(\Redis::class),
            $this->client
        );

        $clearer = new ReverseProxyCacheClearer($this->gateway);
        $clearer->clear('noop');

        static::assertInstanceOf(RequestInterface::class$this->mockHandler->getLastRequest());

        static::assertSame('PURGE', $this->mockHandler->getLastRequest()->getMethod());
        static::assertSame('/', $this->mockHandler->getLastRequest()->getRequestTarget());
        static::assertFalse($this->mockHandler->getLastRequest()->hasHeader('foo'));
    }

    public function testClearWithHeader(): void
    {
        $this->mockHandler->append(new Response(200));

        $clearer = new ReverseProxyCacheClearer($this->gateway);
        $clearer->clear('noop');

        static::assertInstanceOf(RequestInterface::class$this->mockHandler->getLastRequest());

        

    public function testInvalidate(array $tags, string $prefix = ''): void
    {
        $this->mockHandler->append(new GuzzleResponse(200, []));

        $gateway = new FastlyReverseProxyGateway($this->client, 'test', 'key', '0', 3, $prefix, '', 'http://localhost');
        $gateway->invalidate($tags);
        $gateway->flush();

        $lastRequest = $this->mockHandler->getLastRequest();
        static::assertNotNull($lastRequest);
        static::assertSame('/service/test/purge', $lastRequest->getRequestTarget());
        static::assertSame([$prefix . 'foo']$lastRequest->getHeader('surrogate-key'));
        static::assertSame(['key']$lastRequest->getHeader('Fastly-Key'));

        static::assertCount(0, $this->mockHandler);
    }

    public function testInvalidateGoesBeyondLimitOfApi(): void
    {
        $this->mockHandler->append(new GuzzleResponse(200, []));
        $this->mockHandler->append(new GuzzleResponse(200, []));

        
Home | Imprint | This part of the site doesn't use cookies.