Support of Proxy settings

Created on 7 March 2024, 4 months ago
Updated 24 May 2024, about 1 month ago

Problem/Motivation

I would like to use the Drupal's proxy configuration when I'm calling a service through HTTP_CLIENT_MANAGER.

Steps to reproduce

Create a custom module using HTTP_CLIENT_MANAGER. (ex: test_proxy)

  • Define the proxy's settings on your Drupal's settings file.
    $settings['http_client_config']['proxy']['http'] = 'https://<user>:<password>@<location>:<port>';
    $settings['http_client_config']['proxy']['https'] = 'https://<user>:<password>@<location>:<port>';
    $settings['http_client_config']['proxy']['no'] = ['127.0.0.1', 'localhost'];
    
  • Create modules/custom/test_proxy/test_proxy.http_services_api.yml
    beh_services.httpbin:
      title: "[Services] Httpbin"
      api_path: "/src/api/httpbin.yml"
      config:
        base_uri: "https://httpbin.org"
    
  • Create modules/custom/test_proxy/src/api/httpbin.yml
    name: "[Services] Httpbin"
    apiVersion: "1.0"
    description: "Client wrapper Httpbin API."
    imports:
      - "resources/httpbin/content.yml"
    
  • Create modules/custom/test_proxy/src/api/resources/httpbin/content.yml
    operations:
    
      GetContent:
        httpMethod: "GET"
        uri: "/get"
        summary: "Gets the origin."
        responseModel: "ContentData"
    
    models:
    
      ContentData:
        type: "object"
        location: "json"
        properties:
          args:
            type: "json"
            location: "json"
          headers:
            type: "json"
            location: "json"
          origin:
            type: "string"
            location: "json"
          url:
            type: "string"
            location: "json"
    

When I'm testing the service, through the UI, the Origin in the httpbin response is my network IP. It should be the proxy's.

Proposed resolution

TBD.

💬 Support request
Status

Closed: works as designed

Version

3.1

Component

Code

Created by

🇫🇷France fabrer Aix-en-provence

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @fabrer
  • 🇫🇷France fabrer Aix-en-provence

    Update: I revert to use Guzzle calls instead of http_client_manager. However I'm still interested in any answer/help for my next projects.

    Regards,

  • Assigned to aronne
  • 🇮🇹Italy aronne

    Hi @fabrer,
    for you to use proxy when using HTTP Client Manager, all you need to do is just to configure your client in this way:

    beh_services.httpbin:
      title: "[Services] Httpbin"
      api_path: "/src/api/httpbin.yml"
      config:
        base_uri: "https://httpbin.org"
        proxy:
          http: 'https://<user>:<password>@<location>:<port>''
          https: 'https://<user>:<password>@<location>:<port>'
          no: ['127.0.0.1', 'localhost']
    

    And that's it, you're good to go. If you have multiple clients sharing the same proxy configurations, you can create a master client and then extend it. You can find a tutorial on how to do it by looking at the module documentation.

    I tried it by myself:



    Hope it helps.

    Kind regards,
    aronne

  • Status changed to Closed: works as designed about 1 month ago
Production build 0.69.0 2024