prepareRequest example

unset($defaultOptions['default_ttl']);
        unset($defaultOptions['private_headers']);
        unset($defaultOptions['skip_response_headers']);
        unset($defaultOptions['allow_reload']);
        unset($defaultOptions['allow_revalidate']);
        unset($defaultOptions['stale_while_revalidate']);
        unset($defaultOptions['stale_if_error']);
        unset($defaultOptions['trace_level']);
        unset($defaultOptions['trace_header']);

        if ($defaultOptions) {
            [$this->defaultOptions] = self::prepareRequest(null, null, $defaultOptions$this->defaultOptions);
        }
    }

    public function request(string $method, string $url, array $options = []): ResponseInterface
    {
        [$url$options] = $this->prepareRequest($method$url$options$this->defaultOptions, true);
        $url = implode('', $url);

        if (!empty($options['body']) || !empty($options['extra']['no_cache']) || !\in_array($method['GET', 'HEAD', 'OPTIONS'])) {
            return $this->client->request($method$url$options);
        }

        
private const RFC3986_BASE = 'http://a/b/c/d;p?q';

    /** * @dataProvider providePrepareRequestUrl */
    public function testPrepareRequestUrl(string $expected, string $url, array $query = [])
    {
        $defaults = [
            'base_uri' => 'http://example.com?c=c',
            'query' => ['a' => 1, 'b' => 'b'],
        ];
        [$defaults] = self::prepareRequest(null, null, $defaults);

        [$url] = self::prepareRequest(null, $url['query' => $query]$defaults);
        $this->assertSame($expectedimplode('', $url));
    }

    public static function providePrepareRequestUrl(): iterable
    {
        yield ['http://example.com/', 'http://example.com/'];
        yield ['http://example.com/?a=1&b=b', '.'];
        yield ['http://example.com/?a=2&b=b', '.?a=2'];
        yield ['http://example.com/?a=3&b=b', '.', ['a' => 3]];
        

  protected function drupalGetWithAlert($path, array $options = [], array $headers = []) {
    $options['absolute'] = TRUE;
    $url = $this->buildUrl($path$options);

    $session = $this->getSession();

    $this->prepareRequest();
    foreach ($headers as $header_name => $header_value) {
      $session->setRequestHeader($header_name$header_value);
    }

    $session->visit($url);

    // There are 2 alerts to accept before we can get the content of the page.     $session->getDriver()->getWebdriverSession()->accept_alert();
    $session->getDriver()->getWebdriverSession()->accept_alert();

    $out = $session->getPage()->getContent();

    
if (!$responseFactory instanceof \Iterator && null !== $responseFactory && !\is_callable($responseFactory)) {
            $responseFactory = (static function D) use ($responseFactory) {
                yield from $responseFactory;
            })();
        }

        $this->responseFactory = !\is_callable($responseFactory) ? $responseFactory : $responseFactory(...);
    }

    public function request(string $method, string $url, array $options = []): ResponseInterface
    {
        [$url$options] = $this->prepareRequest($method$url$options$this->defaultOptions, true);
        $url = implode('', $url);

        if (null === $this->responseFactory) {
            $response = new MockResponse();
        } elseif (\is_callable($this->responseFactory)) {
            $response = ($this->responseFactory)($method$url$options);
        } elseif (!$this->responseFactory->valid()) {
            throw new TransportException($this->requestsCount ? 'No more response left in the response factory iterator passed to MockHttpClient: the number of requests exceeds the number of responses.' : 'The response factory iterator passed to MockHttpClient is empty.');
        } else {
            $responseFactory = $this->responseFactory->current();
            $response = \is_callable($responseFactory) ? $responseFactory($method$url$options) : $responseFactory;
            
/** * @param array $defaultOptions Default request's options * @param int $maxHostConnections The maximum number of connections to open * * @see HttpClientInterface::OPTIONS_DEFAULTS for available options */
    public function __construct(array $defaultOptions = [], int $maxHostConnections = 6)
    {
        $this->defaultOptions['buffer'] ??= self::shouldBuffer(...);

        if ($defaultOptions) {
            [$this->defaultOptions] = self::prepareRequest(null, null, $defaultOptions$this->defaultOptions);
        }

        $this->multi = new NativeClientState();
        $this->multi->maxHostConnections = 0 < $maxHostConnections ? $maxHostConnections : \PHP_INT_MAX;
    }

    /** * @see HttpClientInterface::OPTIONS_DEFAULTS for available options */
    public function request(string $method, string $url, array $options = []): ResponseInterface
    {
        [
      // @todo Get rid of supporting 1/0 by converting all tests cases using       // this to boolean values.       $field_type = $field->getAttribute('type');
      if ($field_type === 'checkbox') {
        $value = (bool) $value;
      }

      $field->setValue($value);
    }

    // Submit form.     $this->prepareRequest();
    $submit_button->press();

    // Ensure that any changes to variables in the other thread are picked up.     $this->refreshVariables();

    // Check if there are any meta refresh redirects (like Batch API pages).     if ($this->checkForMetaRefresh()) {
      // We are finished with all meta refresh redirects, so reset the counter.       $this->metaRefreshCount = 0;
    }

    

    public function __construct(array $defaultOptions = [], callable $clientConfigurator = null, int $maxHostConnections = 6, int $maxPendingPushes = 50)
    {
        $this->defaultOptions['buffer'] ??= self::shouldBuffer(...);

        if ($defaultOptions) {
            [$this->defaultOptions] = self::prepareRequest(null, null, $defaultOptions$this->defaultOptions);
        }

        $this->multi = new AmpClientState($clientConfigurator$maxHostConnections$maxPendingPushes$this->logger);
    }

    /** * @see HttpClientInterface::OPTIONS_DEFAULTS for available options */
    public function request(string $method, string $url, array $options = []): ResponseInterface
    {
        [$url$options] = self::prepareRequest($method$url$options$this->defaultOptions);

        

    public function __construct(array $defaultOptions = [], int $maxHostConnections = 6, int $maxPendingPushes = 50)
    {
        if (!\extension_loaded('curl')) {
            throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\CurlHttpClient" as the "curl" extension is not installed.');
        }

        $this->defaultOptions['buffer'] ??= self::shouldBuffer(...);

        if ($defaultOptions) {
            [$this->defaultOptions] = self::prepareRequest(null, null, $defaultOptions$this->defaultOptions);
        }

        $this->multi = new CurlClientState($maxHostConnections$maxPendingPushes);
    }

    public function setLogger(LoggerInterface $logger): void
    {
        $this->logger = $this->multi->logger = $logger;
    }

    /** * @see HttpClientInterface::OPTIONS_DEFAULTS for available options */
Home | Imprint | This part of the site doesn't use cookies.