Skip to content

HTTPClient not support HTTP/HTTPS proxy #4269

Closed

Description

@HADB

Past Issues Searched

  • I have searched open and closed issues to make sure that the bug has not yet been reported

Issue is a Bug Report

  • This is a bug report and not a feature request, nor asking for self-hosted support

Using official Plausible Cloud hosting or self-hosting?

Self-hosting

Describe the bug

First of all, thank you for the great work on this project!

Currently, the HTTPClient seems not support using HTTP or HTTPS proxies set via environment variables (HTTP_PROXY and HTTPS_PROXY). This functionality is important for users who need to route traffic through a proxy for various reasons, such as network restrictions or privacy concerns.

In my case, I'm facing network restrictions while connecting to Google services or Gravartor avatars.

Expected behavior

The HTTPClient should respect the HTTP_PROXY / HTTPS_PROXY environment variables and route HTTP/HTTPS requests through the specified proxy.

Screenshots

No response

Environment

No response

Activity

  1. ruslandoga commented on Jun 24, 2024

    @ruslandoga
    Contributor

    👋 @HADB

    Where do the HTTP_PROXY and HTTPS_PROXY environment variables come from? Have they been documented somewhere?
    I don't think we have them anywhere in the code base.

  2. added
    self-hosting
    on Jun 24, 2024
  3. self-assigned this
    on Jun 24, 2024
  4. HADB commented on Jun 24, 2024

    @HADB
    Author

    @ruslandoga Hi, thanks for replying. HTTP_PROXY and HTTPS_PROXY are environment variables used to specify proxy servers for HTTP and HTTPS traffic respectively. Many applications and libraries recognize and use these variables to route their network traffic through specified proxy servers, such as:curl, wget and Python’s requests library.

  5. ruslandoga commented on Jun 24, 2024

    @ruslandoga
    Contributor

    I see. We might be able to provide support for these env vars later, but for now we can at least make proxying configurable via custom config files. I'll open a PR for that later today with an example configuration.

  6. ruslandoga commented on Jun 24, 2024

    @ruslandoga
    Contributor

    @HADB would you be able to try out the image I built from #4270?

    Here're the changes you'd need to make:

    docker-compose.yml

    plausible:
    - image: ghcr.io/plausible/community-edition:v2.1.1
    + image: ghcr.io/ruslandoga/plausible:build-allow-finch-config-9456444
    + volumes:
    +   - ./my_config.exs:/app/my_config.exs

    my_config.exs

    import Config
    
    # Plausible uses HTTPS for all outgoing requests, and our HTTP client (Mint) doesn't support HTTPS->HTTPS proxying
    # https://hexdocs.pm/mint/Mint.HTTP.html#connect/4-proxying recommends HTTP->HTTPS in this case
    config :plausible, Plausible.Finch, conn_opts: [proxy: {:http, _host = "some.proxy.com", _port = 1080, _opts = []}]

    Note that you would need to provide your own proxy host/port pair. There is also an example config in #4270 where host and port are extracted from HTTP_PROXY env var.

    plausible-conf.env

    + EXTRA_CONFIG_PATH=/app/my_config.exs
  7. HADB commented on Jun 27, 2024

    @HADB
    Author

    @ruslandoga I have tried this image and it works as expected! Great job! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

self-hosting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions