- Issue created by @wrd-oaitsd
- 🇮🇹Italy emanuelrighetto Verona
Hi @ wrd-oaitsd
sorry for the huge delay.You can achieve what you want by adding options to your "Http Services Api" definition via *.http_services_api.yml file.
sorry for the huge delay.
You can achieve what you want by adding options to your "Http Services Api" definition via "*.http_services_ api.yaml" file.
Take a look at the example implementation here https://git.drupalcode.org/project/http_client_manager/-/blob/10.x/modules/http_client_manager_example/http_client_manager_example.http_services_api.yml?You can add any custom value like these:
example_services: title: "[JSON] - Example Services fake API" api_path: "src/api/example_services.json" config: base_uri: "http://jsonplaceholder.typicode.com" curl: 'CURLOPT_SSL_VERIFYPEER': true 'CURLOPT_CAINFO': "/path/to/cacert.pem"
You can also achieve the same result by entering extra configurations in the configuration form at 'admin/config/services/http-client-manager/settings':
But if you have more complex needs you can exploit the "onHandlerStack" event, see the example here: https://git.drupalcode.org/project/http_client_manager/-/blob/10.x/modules/http_client_manager_example/src/EventSubscriber/HttpClientManagerExampleSubscriber.php
You can create your own EventSuscriber where you can override the handler as you wish:
/** * This method is called whenever the http_client.handler_stack event is * dispatched. * * @param \Drupal\http_client_manager\Event\HttpClientHandlerStackEvent $event * The HTTP Client Handler stack event. */ public function onHandlerStack(HttpClientHandlerStackEvent $event) { if ($event->getHttpServiceApi() != 'example_services') { return; } $stack = $event->getHandlerStack(); $stack->setHandler(new CustomCurlHandler()); }
where CustomCurlHandler is defined like that:
declare(strict_types=1); namespace Drupal\your_custom_module; use GuzzleHttp\Handler\CurlHandler; use GuzzleHttp\Promise\PromiseInterface; use Psr\Http\Message\RequestInterface; class CustomCurlHandler extends CurlHandler { /** * @param RequestInterface $request * @param array $options * @return PromiseInterface */ public function __invoke(RequestInterface $request, array $options): PromiseInterface { // Change cURL options here $options['curl'][CURLOPT_SSL_VERIFYPEER] = false; $options['curl'][CURLOPT_TIMEOUT] = 666; return parent::__invoke($request, $options); } }
- Status changed to Closed: works as designed
5 months ago 7:18am 2 July 2024