function AdvisoryTestClientMiddleware::__invoke
Same name and namespace in other branches
- 10 core/modules/system/tests/modules/advisory_feed_test/src/AdvisoryTestClientMiddleware.php \Drupal\advisory_feed_test\AdvisoryTestClientMiddleware::__invoke()
HTTP middleware that replaces URI for advisory requests.
File
-
core/
modules/ system/ tests/ modules/ advisory_feed_test/ src/ AdvisoryTestClientMiddleware.php, line 17
Class
- AdvisoryTestClientMiddleware
- Overrides the User-Agent HTTP header for outbound HTTP requests.
Namespace
Drupal\advisory_feed_testCode
public function __invoke() {
return function ($handler) {
return function (RequestInterface $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);
};
};
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.