class AdvisoryTestClientMiddleware
Same name in other branches
- 11.x core/modules/system/tests/modules/advisory_feed_test/src/AdvisoryTestClientMiddleware.php \Drupal\advisory_feed_test\AdvisoryTestClientMiddleware
Overrides the User-Agent HTTP header for outbound HTTP requests.
Hierarchy
- class \Drupal\advisory_feed_test\AdvisoryTestClientMiddleware
Expanded class hierarchy of AdvisoryTestClientMiddleware
1 file declares its use of AdvisoryTestClientMiddleware
- SecurityAdvisoryTest.php in core/
modules/ system/ tests/ src/ Functional/ SecurityAdvisories/ SecurityAdvisoryTest.php
1 string reference to 'AdvisoryTestClientMiddleware'
- advisory_feed_test.services.yml in core/
modules/ system/ tests/ modules/ advisory_feed_test/ advisory_feed_test.services.yml - core/modules/system/tests/modules/advisory_feed_test/advisory_feed_test.services.yml
1 service uses AdvisoryTestClientMiddleware
- http_client.advisory_feed_test in core/
modules/ system/ tests/ modules/ advisory_feed_test/ advisory_feed_test.services.yml - Drupal\advisory_feed_test\AdvisoryTestClientMiddleware
File
-
core/
modules/ system/ tests/ modules/ advisory_feed_test/ src/ AdvisoryTestClientMiddleware.php, line 12
Namespace
Drupal\advisory_feed_testView source
class AdvisoryTestClientMiddleware {
/**
* HTTP middleware that replaces URI for advisory requests.
*/
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((string) $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 static function setTestEndpoint(string $test_endpoint, bool $delete_stored_response = FALSE) : void {
\Drupal::state()->set('advisories_test_endpoint', $test_endpoint);
if ($delete_stored_response) {
\Drupal::service('system.sa_fetcher')->deleteStoredResponse();
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
AdvisoryTestClientMiddleware::setTestEndpoint | public static | function | Sets the test endpoint for the advisories JSON feed. |
AdvisoryTestClientMiddleware::__invoke | public | function | HTTP middleware that replaces URI for advisory requests. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.