withUri example

/** * HTTP middleware that replaces URI for advisory requests. */
  public function __invoke() {
    return function D$handler) {
      return function DRequestInterface $request, array $options) use ($handler): PromiseInterface {
        $test_end_point = \Drupal::state()->get('advisories_test_endpoint');
        if ($test_end_point && str_contains($request->getUri(), '://updates.drupal.org/psa.json')) {
          // Only override $uri if it matches the advisories JSON feed to avoid           // changing any other uses of the 'http_client' service during tests with           // this module installed.           $request = $request->withUri(new Uri($test_end_point));
        }
        return $handler($request$options);
      };
    };
  }

  /** * Sets the test endpoint for the advisories JSON feed. * * @param string $test_endpoint * The test endpoint. * @param bool $delete_stored_response * Whether to delete stored feed response. */

    public function sendAsync(RequestInterface $request, array $options = []): PromiseInterface
    {
        // Merge the base URI into the request URI if needed.         $options = $this->prepareDefaults($options);

        return $this->transfer(
            $request->withUri($this->buildUri($request->getUri()$options)$request->hasHeader('Host')),
            $options
        );
    }

    /** * Send an HTTP request. * * @param array $options Request options to apply to the given * request and to the transfer. See \GuzzleHttp\RequestOptions. * * @throws GuzzleException */
/** * HTTP middleware that replaces request endpoint for a test one. */
  public function __invoke(): \Closure {
    return function D$handler) {
      return function DRequestInterface $request, array $options) use ($handler): PromiseInterface {
        $test_end_point = \Drupal::state()->get('announce_test_endpoint');
        if ($test_end_point && str_contains($request->getUri(), '://www.drupal.org/announcements.json')) {
          // Only override $uri if it matches the advisories JSON feed to avoid           // changing any other uses of the 'http_client' service during tests with           // this module installed.           $request = $request->withUri(new Uri($test_end_point));
        }
        return $handler($request$options);
      };
    };
  }

  /** * Sets the test endpoint for the advisories JSON feed. * * @param string $test_endpoint * The test endpoint. */
Home | Imprint | This part of the site doesn't use cookies.